From cf4b1ddb645894a384a925e70b2ea0d01a4440d1 Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 14:24:15 +0300 Subject: [PATCH 01/13] add CARDINALS constant to Dir2 and Dir3 --- crates/bevy_math/src/direction.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 03cb9f969f1e6..0cdafdb044df0 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -21,7 +21,7 @@ use thiserror::Error; /// An error indicating that a direction is invalid. #[derive(Debug, PartialEq, Error)] pub enum InvalidDirectionError { - /// The length of the direction vector is zero or very close to zero. + /// The length of the direction vector is zero or very close to zero.XES #[error("The length of the direction vector is zero or very close to zero")] Zero, /// The length of the direction vector is `std::f32::INFINITY`. @@ -107,6 +107,8 @@ impl Dir2 { pub const NEG_Y: Self = Self(Vec2::NEG_Y); /// The directional axes. pub const AXES: [Self; 2] = [Self::X, Self::Y]; + /// The cardinal directions. + pub const CARDINALS: [Self; 4] = [Self::X, Self::NEG_X, Self::Y, Self::NEG_Y]; /// The "north" direction, equivalent to [`Dir2::Y`]. pub const NORTH: Self = Self(Vec2::Y); @@ -395,6 +397,8 @@ impl Dir3 { pub const NEG_Z: Self = Self(Vec3::NEG_Z); /// The directional axes. pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z]; + /// The cardinal directions. + pub const CARDINALS: [Self; 6] = [Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z]; /// Create a direction from a finite, nonzero [`Vec3`], normalizing it. /// From 9b2e9e1b6cd772f2dd99945be1ec501195416bdf Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 14:41:09 +0300 Subject: [PATCH 02/13] added the DIAGONALS const --- crates/bevy_math/src/direction.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 0cdafdb044df0..477a42569124a 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -127,6 +127,9 @@ impl Dir2 { /// The "south-west" direction, between [`Dir2::SOUTH`] and [`Dir2::WEST`]. pub const SOUTH_WEST: Self = Self(Vec2::new(-FRAC_1_SQRT_2, -FRAC_1_SQRT_2)); + /// The diagonals between the cardinal directions. + pub const DIAGONALS: [Self; 4] = [Self::NORTH_EAST, Self::NORTH_WEST, Self::SOUTH_EAST, Self::SOUTH_WEST]; + /// Create a direction from a finite, nonzero [`Vec2`], normalizing it. /// /// Returns [`Err(InvalidDirectionError)`](InvalidDirectionError) if the length @@ -400,6 +403,20 @@ impl Dir3 { /// The cardinal directions. pub const CARDINALS: [Self; 6] = [Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z]; + // Value taken with same precision as FRAC_1_SQRT_2 + const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957455f32; + /// The diagonals between the cardinal directions. + pub const DIAGONALS: [Self; 8] = [ + Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + ]; + /// Create a direction from a finite, nonzero [`Vec3`], normalizing it. /// /// Returns [`Err(InvalidDirectionError)`](InvalidDirectionError) if the length From c10d08fbb15d50130e3ebfd045138c9089f644fe Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 14:44:57 +0300 Subject: [PATCH 03/13] added ALL_NEIGHBORS constant --- crates/bevy_math/src/direction.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 477a42569124a..20bfd3c26a836 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -129,6 +129,11 @@ impl Dir2 { /// The diagonals between the cardinal directions. pub const DIAGONALS: [Self; 4] = [Self::NORTH_EAST, Self::NORTH_WEST, Self::SOUTH_EAST, Self::SOUTH_WEST]; + /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] + pub const ALL_NEIGHBORS: [Self; 8] = [ + Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, + Self::NORTH_EAST, Self::NORTH_WEST, Self::SOUTH_EAST, Self::SOUTH_WEST + ]; /// Create a direction from a finite, nonzero [`Vec2`], normalizing it. /// @@ -403,7 +408,7 @@ impl Dir3 { /// The cardinal directions. pub const CARDINALS: [Self; 6] = [Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z]; - // Value taken with same precision as FRAC_1_SQRT_2 + /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957455f32; /// The diagonals between the cardinal directions. pub const DIAGONALS: [Self; 8] = [ @@ -416,6 +421,19 @@ impl Dir3 { Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), ]; + /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] + pub const ALL_NEIGHBORS: [Self; 14] = [ + Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z, + Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), + Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + ]; + /// Create a direction from a finite, nonzero [`Vec3`], normalizing it. /// From 35ab1726930da8a5f44fc9cb892823c0d6918958 Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 14:45:28 +0300 Subject: [PATCH 04/13] applied formatter to new changes --- crates/bevy_math/src/direction.rs | 130 +++++++++++++++++++++++++----- 1 file changed, 108 insertions(+), 22 deletions(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 20bfd3c26a836..068b8ba4fdf63 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -128,11 +128,22 @@ impl Dir2 { pub const SOUTH_WEST: Self = Self(Vec2::new(-FRAC_1_SQRT_2, -FRAC_1_SQRT_2)); /// The diagonals between the cardinal directions. - pub const DIAGONALS: [Self; 4] = [Self::NORTH_EAST, Self::NORTH_WEST, Self::SOUTH_EAST, Self::SOUTH_WEST]; + pub const DIAGONALS: [Self; 4] = [ + Self::NORTH_EAST, + Self::NORTH_WEST, + Self::SOUTH_EAST, + Self::SOUTH_WEST, + ]; /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] pub const ALL_NEIGHBORS: [Self; 8] = [ - Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, - Self::NORTH_EAST, Self::NORTH_WEST, Self::SOUTH_EAST, Self::SOUTH_WEST + Self::X, + Self::NEG_X, + Self::Y, + Self::NEG_Y, + Self::NORTH_EAST, + Self::NORTH_WEST, + Self::SOUTH_EAST, + Self::SOUTH_WEST, ]; /// Create a direction from a finite, nonzero [`Vec2`], normalizing it. @@ -406,35 +417,110 @@ impl Dir3 { /// The directional axes. pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z]; /// The cardinal directions. - pub const CARDINALS: [Self; 6] = [Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z]; + pub const CARDINALS: [Self; 6] = [ + Self::X, + Self::NEG_X, + Self::Y, + Self::NEG_Y, + Self::Z, + Self::NEG_Z, + ]; /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957455f32; /// The diagonals between the cardinal directions. pub const DIAGONALS: [Self; 8] = [ - Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), - Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), ]; /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] pub const ALL_NEIGHBORS: [Self; 14] = [ - Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z, - Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3)), - Self(Vec3::new(Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), - Self(Vec3::new(Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), - Self(Vec3::new(-Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3, -Self::FRAC_1_SQRT_3)), + Self::X, + Self::NEG_X, + Self::Y, + Self::NEG_Y, + Self::Z, + Self::NEG_Z, + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), + Self(Vec3::new( + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + -Self::FRAC_1_SQRT_3, + )), ]; - /// Create a direction from a finite, nonzero [`Vec3`], normalizing it. /// /// Returns [`Err(InvalidDirectionError)`](InvalidDirectionError) if the length From a913e2b2cb6cb8b39b303c41c98107b77f53161a Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 14:57:40 +0300 Subject: [PATCH 05/13] fix clippy warning about precision --- crates/bevy_math/src/direction.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 068b8ba4fdf63..79d1c4195beca 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -426,6 +426,9 @@ impl Dir3 { Self::NEG_Z, ]; + // Adding this allow here to make sure that the precision in FRAC_1_SQRT_2 + // and here is the same + #[allow(clippy::excessive_precision)] /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957455f32; /// The diagonals between the cardinal directions. From 003b605b340447916a75e1e0a078c4ced580a205 Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 15:02:23 +0300 Subject: [PATCH 06/13] updated the 1/sqrt(3) const to be in line with the unstable rust definition for compat reasons --- crates/bevy_math/src/direction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 79d1c4195beca..6c287185c3452 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -430,7 +430,7 @@ impl Dir3 { // and here is the same #[allow(clippy::excessive_precision)] /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space - const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957455f32; + const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957456_f32; /// The diagonals between the cardinal directions. pub const DIAGONALS: [Self; 8] = [ Self(Vec3::new( From 99986ccc2e590965b155ad63866f5339837ff8a8 Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 15:10:14 +0300 Subject: [PATCH 07/13] added reason for allow of excessive precision --- crates/bevy_math/src/direction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 6c287185c3452..c800ce7eccaf8 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -428,7 +428,7 @@ impl Dir3 { // Adding this allow here to make sure that the precision in FRAC_1_SQRT_2 // and here is the same - #[allow(clippy::excessive_precision)] + #[allow(clippy::excessive_precision, reason="compatability with the unstable rust definition")] /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957456_f32; /// The diagonals between the cardinal directions. From 4be20e851d112aa021535da1ed25997a0ed1269d Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 15:17:41 +0300 Subject: [PATCH 08/13] replaced allow with expect as per CI hint --- crates/bevy_math/src/direction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index c800ce7eccaf8..fbcbb5472b9e5 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -428,7 +428,7 @@ impl Dir3 { // Adding this allow here to make sure that the precision in FRAC_1_SQRT_2 // and here is the same - #[allow(clippy::excessive_precision, reason="compatability with the unstable rust definition")] + #[expect(clippy::excessive_precision, reason="compatability with the unstable rust definition")] /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957456_f32; /// The diagonals between the cardinal directions. From ddf0d5a7b1af3e1b34b4caa385200c2e8e3ce756 Mon Sep 17 00:00:00 2001 From: Alexander Kurkotov Date: Thu, 16 Oct 2025 15:41:35 +0300 Subject: [PATCH 09/13] formatting and typo fixes --- crates/bevy_math/src/direction.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index fbcbb5472b9e5..c6a4abd6c1e6a 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -428,7 +428,10 @@ impl Dir3 { // Adding this allow here to make sure that the precision in FRAC_1_SQRT_2 // and here is the same - #[expect(clippy::excessive_precision, reason="compatability with the unstable rust definition")] + #[expect( + clippy::excessive_precision, + reason = "compatibility with the unstable rust definition" + )] /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957456_f32; /// The diagonals between the cardinal directions. From 91452e22a5aee8ae17acdd58e1d11b3e1f2e7499 Mon Sep 17 00:00:00 2001 From: Freya Pines Date: Fri, 17 Oct 2025 14:18:25 +0300 Subject: [PATCH 10/13] added ALL_EDGES group and fixed the ALL_NEIGHBORS to have all the neighboring directions --- crates/bevy_math/src/direction.rs | 35 +++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index c6a4abd6c1e6a..aba1e3bc4fb2f 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -434,8 +434,8 @@ impl Dir3 { )] /// Approximation of 1/sqrt(3) needed for the diagonals in 3D space const FRAC_1_SQRT_3: f32 = 0.577350269189625764509148780501957456_f32; - /// The diagonals between the cardinal directions. - pub const DIAGONALS: [Self; 8] = [ + /// The directions pointing towards the vertices of a cube centered at the origin. + pub const ALL_VERTICES: [Self; 8] = [ Self(Vec3::new( Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, @@ -477,14 +477,41 @@ impl Dir3 { -Self::FRAC_1_SQRT_3, )), ]; - /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] - pub const ALL_NEIGHBORS: [Self; 14] = [ + /// The directions towards centres of each edge of a cube + pub const ALL_EDGES: [Self; 12] = [ + Self(Vec3::new(FRAC_1_SQRT_2, FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(-FRAC_1_SQRT_2, FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(FRAC_1_SQRT_2, -FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(-FRAC_1_SQRT_2, -FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(FRAC_1_SQRT_2, 0., FRAC_1_SQRT_2)), + Self(Vec3::new(-FRAC_1_SQRT_2, 0., FRAC_1_SQRT_2)), + Self(Vec3::new(FRAC_1_SQRT_2, 0., -FRAC_1_SQRT_2)), + Self(Vec3::new(-FRAC_1_SQRT_2, 0., -FRAC_1_SQRT_2)), + Self(Vec3::new(0., FRAC_1_SQRT_2, FRAC_1_SQRT_2)), + Self(Vec3::new(0., -FRAC_1_SQRT_2, FRAC_1_SQRT_2)), + Self(Vec3::new(0., FRAC_1_SQRT_2, -FRAC_1_SQRT_2)), + Self(Vec3::new(0., -FRAC_1_SQRT_2, -FRAC_1_SQRT_2)), + ]; + /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`], [`Self::ALL_EDGES`] and [`Self::ALL_VERTICES`] + pub const ALL_NEIGHBORS: [Self; 26] = [ Self::X, Self::NEG_X, Self::Y, Self::NEG_Y, Self::Z, Self::NEG_Z, + Self(Vec3::new(FRAC_1_SQRT_2, FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(-FRAC_1_SQRT_2, FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(FRAC_1_SQRT_2, -FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(-FRAC_1_SQRT_2, -FRAC_1_SQRT_2, 0.)), + Self(Vec3::new(FRAC_1_SQRT_2, 0., FRAC_1_SQRT_2)), + Self(Vec3::new(-FRAC_1_SQRT_2, 0., FRAC_1_SQRT_2)), + Self(Vec3::new(FRAC_1_SQRT_2, 0., -FRAC_1_SQRT_2)), + Self(Vec3::new(-FRAC_1_SQRT_2, 0., -FRAC_1_SQRT_2)), + Self(Vec3::new(0., FRAC_1_SQRT_2, FRAC_1_SQRT_2)), + Self(Vec3::new(0., -FRAC_1_SQRT_2, FRAC_1_SQRT_2)), + Self(Vec3::new(0., FRAC_1_SQRT_2, -FRAC_1_SQRT_2)), + Self(Vec3::new(0., -FRAC_1_SQRT_2, -FRAC_1_SQRT_2)), Self(Vec3::new( Self::FRAC_1_SQRT_3, Self::FRAC_1_SQRT_3, From f6c17896635ef6632c177c239b5f90b8f07a7794 Mon Sep 17 00:00:00 2001 From: Freya Pines Date: Fri, 17 Oct 2025 14:21:56 +0300 Subject: [PATCH 11/13] fix documentation terminology for neighbors --- crates/bevy_math/src/direction.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index aba1e3bc4fb2f..56860a6204ab1 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -134,7 +134,7 @@ impl Dir2 { Self::SOUTH_EAST, Self::SOUTH_WEST, ]; - /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] + /// All neighbors of a tile on a square grid in a 3x3 neighborhood. A combination of [`Self::CARDINALS`] and [`Self::DIAGONALS`] pub const ALL_NEIGHBORS: [Self; 8] = [ Self::X, Self::NEG_X, @@ -492,7 +492,7 @@ impl Dir3 { Self(Vec3::new(0., FRAC_1_SQRT_2, -FRAC_1_SQRT_2)), Self(Vec3::new(0., -FRAC_1_SQRT_2, -FRAC_1_SQRT_2)), ]; - /// All neighboring directions on a grid. A combination of [`Self::CARDINALS`], [`Self::ALL_EDGES`] and [`Self::ALL_VERTICES`] + /// All neighbors of a tile on a cube grid a 3x3x3 neighborhood. A combination of [`Self::CARDINALS`], [`Self::ALL_EDGES`] and [`Self::ALL_VERTICES`] pub const ALL_NEIGHBORS: [Self; 26] = [ Self::X, Self::NEG_X, From 621263bd93f01428f78c2ad3925fc97b96602246 Mon Sep 17 00:00:00 2001 From: Freya Pines Date: Fri, 17 Oct 2025 14:27:15 +0300 Subject: [PATCH 12/13] fix typos --- crates/bevy_math/src/direction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 56860a6204ab1..8df39564a010d 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -477,7 +477,7 @@ impl Dir3 { -Self::FRAC_1_SQRT_3, )), ]; - /// The directions towards centres of each edge of a cube + /// The directions towards centers of each edge of a cube pub const ALL_EDGES: [Self; 12] = [ Self(Vec3::new(FRAC_1_SQRT_2, FRAC_1_SQRT_2, 0.)), Self(Vec3::new(-FRAC_1_SQRT_2, FRAC_1_SQRT_2, 0.)), From a8f891d68ede65349200f0809c6667255771a124 Mon Sep 17 00:00:00 2001 From: Freya Pines Date: Fri, 17 Oct 2025 14:42:15 +0300 Subject: [PATCH 13/13] Update crates/bevy_math/src/direction.rs fix typo Co-authored-by: Joona Aalto --- crates/bevy_math/src/direction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 8df39564a010d..509e497b43040 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -21,7 +21,7 @@ use thiserror::Error; /// An error indicating that a direction is invalid. #[derive(Debug, PartialEq, Error)] pub enum InvalidDirectionError { - /// The length of the direction vector is zero or very close to zero.XES + /// The length of the direction vector is zero or very close to zero. #[error("The length of the direction vector is zero or very close to zero")] Zero, /// The length of the direction vector is `std::f32::INFINITY`.