Skip to content

Commit

Permalink
Add Direction3dA and move direction types out of primitives (#12018)
Browse files Browse the repository at this point in the history
# Objective

Split up from #12017, add an aligned version of `Direction3d` for SIMD,
and move direction types out of `primitives`.

## Solution

Add `Direction3dA` and move direction types into a new `direction`
module.

---

## Migration Guide

The `Direction2d`, `Direction3d`, and `InvalidDirectionError` types have
been moved out of `bevy::math::primitives`.

Before:

```rust
use bevy::math::primitives::Direction3d;
```

After:

```rust
use bevy::math::Direction3d;
```

---------

Co-authored-by: Alice Cecile <[email protected]>
  • Loading branch information
Jondolf and alice-i-cecile authored Feb 26, 2024
1 parent f939c09 commit 9bd6cc0
Show file tree
Hide file tree
Showing 22 changed files with 598 additions and 371 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/circles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::prelude::{GizmoConfigGroup, Gizmos};
use bevy_math::Mat2;
use bevy_math::{primitives::Direction3d, Quat, Vec2, Vec3};
use bevy_math::{Direction3d, Quat, Vec2, Vec3};
use bevy_render::color::LegacyColor;
use std::f32::consts::TAU;

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy_ecs::{
system::{Deferred, ReadOnlySystemParam, Res, Resource, SystemBuffer, SystemMeta, SystemParam},
world::{unsafe_world_cell::UnsafeWorldCell, World},
};
use bevy_math::{primitives::Direction3d, Mat2, Quat, Vec2, Vec3};
use bevy_math::{Direction3d, Mat2, Quat, Vec2, Vec3};
use bevy_render::color::LegacyColor;
use bevy_transform::TransformPoint;

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_gizmos/src/primitives/dim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::f32::consts::PI;
use super::helpers::*;

use bevy_math::primitives::{
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Direction2d, Ellipse, Line2d, Plane2d,
Polygon, Polyline2d, Primitive2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon,
Polyline2d, Primitive2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
};
use bevy_math::{Mat2, Vec2};
use bevy_math::{Direction2d, Mat2, Vec2};
use bevy_render::color::LegacyColor;

use crate::prelude::{GizmoConfigGroup, Gizmos};
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_gizmos/src/primitives/dim3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use super::helpers::*;
use std::f32::consts::TAU;

use bevy_math::primitives::{
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Direction3d, Line3d,
Plane3d, Polyline3d, Primitive3d, Segment3d, Sphere, Torus,
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d,
Polyline3d, Primitive3d, Segment3d, Sphere, Torus,
};
use bevy_math::{Quat, Vec3};
use bevy_math::{Direction3d, Quat, Vec3};
use bevy_render::color::LegacyColor;

use crate::prelude::{GizmoConfigGroup, Gizmos};
Expand Down
16 changes: 9 additions & 7 deletions crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Contains [`Bounded2d`] implementations for [geometric primitives](crate::primitives).
use glam::{Mat2, Vec2};

use crate::primitives::{
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Direction2d, Ellipse, Line2d, Plane2d,
Polygon, Polyline2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
use crate::{
primitives::{
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon,
Polyline2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
},
Direction2d, Mat2, Vec2,
};

use super::{Aabb2d, Bounded2d, BoundingCircle};
Expand Down Expand Up @@ -262,9 +263,10 @@ mod tests {
use crate::{
bounding::Bounded2d,
primitives::{
Capsule2d, Circle, Direction2d, Ellipse, Line2d, Plane2d, Polygon, Polyline2d,
Rectangle, RegularPolygon, Segment2d, Triangle2d,
Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon, Polyline2d, Rectangle,
RegularPolygon, Segment2d, Triangle2d,
},
Direction2d,
};

#[test]
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_math/src/bounding/bounded3d/primitive_impls.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Contains [`Bounded3d`] implementations for [geometric primitives](crate::primitives).
use glam::{Mat3, Quat, Vec2, Vec3};

use crate::{
bounding::{Bounded2d, BoundingCircle},
primitives::{
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Direction3d, Line3d,
Plane3d, Polyline3d, Segment3d, Sphere, Torus, Triangle2d,
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d,
Polyline3d, Segment3d, Sphere, Torus, Triangle2d,
},
Direction3d, Mat3, Quat, Vec2, Vec3,
};

use super::{Aabb3d, Bounded3d, BoundingSphere};
Expand Down Expand Up @@ -311,9 +310,10 @@ mod tests {
use crate::{
bounding::Bounded3d,
primitives::{
Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Direction3d, Line3d, Plane3d,
Polyline3d, Segment3d, Sphere, Torus,
Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d, Polyline3d,
Segment3d, Sphere, Torus,
},
Direction3d,
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/bounding/raycast2d.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Aabb2d, BoundingCircle, IntersectsVolume};
use crate::{primitives::Direction2d, Ray2d, Vec2};
use crate::{Direction2d, Ray2d, Vec2};

/// A raycast intersection test for 2D bounding volumes
#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/bounding/raycast3d.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Aabb3d, BoundingSphere, IntersectsVolume};
use crate::{primitives::Direction3d, Ray3d, Vec3};
use crate::{Direction3d, Ray3d, Vec3};

/// A raycast intersection test for 3D bounding volumes
#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit 9bd6cc0

Please sign in to comment.