Skip to content

Rename Direction2d/Direction3d to Dir2/Dir3 and add Dir3A #12017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 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::{Dir3, Quat, Vec2, Vec3};
use bevy_render::color::Color;
use std::f32::consts::TAU;

Expand Down Expand Up @@ -106,12 +106,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.circle(Vec3::ZERO, Direction3d::Z, 1., Color::GREEN);
/// gizmos.circle(Vec3::ZERO, Dir3::Z, 1., Color::GREEN);
///
/// // Circles have 32 line-segments by default.
/// // You may want to increase this for larger circles.
/// gizmos
/// .circle(Vec3::ZERO, Direction3d::Z, 5., Color::RED)
/// .circle(Vec3::ZERO, Dir3::Z, 5., Color::RED)
/// .segments(64);
/// }
/// # bevy_ecs::system::assert_is_system(system);
Expand All @@ -120,7 +120,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
pub fn circle(
&mut self,
position: Vec3,
normal: Direction3d,
normal: Dir3,
radius: f32,
color: Color,
) -> EllipseBuilder<'_, 'w, 's, T> {
Expand Down
4 changes: 2 additions & 2 deletions 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::{Dir3, Mat2, Quat, Vec2, Vec3};
use bevy_render::color::Color;
use bevy_transform::TransformPoint;

Expand Down Expand Up @@ -622,7 +622,7 @@ impl<T: GizmoConfigGroup> Drop for SphereBuilder<'_, '_, '_, T> {
self.gizmos
.circle(
self.position,
Direction3d::new_unchecked(self.rotation * axis),
Dir3::new_unchecked(self.rotation * axis),
self.radius,
self.color,
)
Expand Down
18 changes: 9 additions & 9 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::{Dir2, Mat2, Vec2};
use bevy_render::color::Color;

use crate::prelude::{GizmoConfigGroup, Gizmos};
Expand Down Expand Up @@ -38,12 +38,12 @@ pub trait GizmoPrimitive2d<P: Primitive2d> {

// direction 2d

impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Direction2d> for Gizmos<'w, 's, T> {
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Dir2> for Gizmos<'w, 's, T> {
type Output<'a> = () where Self : 'a;

fn primitive_2d(
&mut self,
primitive: Direction2d,
primitive: Dir2,
position: Vec2,
angle: f32,
color: Color,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's,
pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
gizmos: &'a mut Gizmos<'w, 's, T>,

direction: Direction2d, // Direction of the line
direction: Dir2, // Direction of the line

position: Vec2, // position of the center of the line
rotation: Mat2, // rotation of the line
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T
.draw_arrow(true);

// draw the plane line
let direction = Direction2d::new_unchecked(-normal.perp());
let direction = Dir2::new_unchecked(-normal.perp());
self.primitive_2d(Line2d { direction }, position, angle, color)
.draw_arrow(false);

Expand All @@ -282,8 +282,8 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, T
pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
gizmos: &'a mut Gizmos<'w, 's, T>,

direction: Direction2d, // Direction of the line segment
half_length: f32, // Half-length of the line segment
direction: Dir2, // Direction of the line segment
half_length: f32, // Half-length of the line segment

position: Vec2, // position of the center of the line segment
rotation: Mat2, // rotation of the line segment
Expand Down
14 changes: 7 additions & 7 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::{Dir3, Quat, Vec3};
use bevy_render::color::Color;

use crate::prelude::{GizmoConfigGroup, Gizmos};
Expand Down Expand Up @@ -35,12 +35,12 @@ pub trait GizmoPrimitive3d<P: Primitive3d> {

// direction 3d

impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Direction3d> for Gizmos<'w, 's, T> {
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Dir3> for Gizmos<'w, 's, T> {
type Output<'a> = () where Self: 'a;

fn primitive_3d(
&mut self,
primitive: Direction3d,
primitive: Dir3,
position: Vec3,
rotation: Quat,
color: Color,
Expand Down Expand Up @@ -139,7 +139,7 @@ pub struct Plane3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
gizmos: &'a mut Gizmos<'w, 's, T>,

// direction of the normal orthogonal to the plane
normal: Direction3d,
normal: Dir3,

// Rotation of the sphere around the origin in 3D space
rotation: Quat,
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<T: GizmoConfigGroup> Drop for Plane3dBuilder<'_, '_, '_, T> {
.map(|angle| Quat::from_axis_angle(normal, angle))
.for_each(|quat| {
let axis_direction = quat * normals_normal;
let direction = Direction3d::new_unchecked(axis_direction);
let direction = Dir3::new_unchecked(axis_direction);

// for each axis draw dotted line
(0..)
Expand Down
35 changes: 14 additions & 21 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,
},
{Dir2, Mat2, Vec2},
};

use super::{Aabb2d, Bounded2d, BoundingCircle};
Expand Down Expand Up @@ -235,7 +236,7 @@ impl Bounded2d for Capsule2d {
// Get the line segment between the hemicircles of the rotated capsule
let segment = Segment2d {
// Multiplying a normalized vector (Vec2::Y) with a rotation returns a normalized vector.
direction: Direction2d::new_unchecked(Mat2::from_angle(rotation) * Vec2::Y),
direction: Dir2::new_unchecked(Mat2::from_angle(rotation) * Vec2::Y),
half_length: self.half_length,
};
let (a, b) = (segment.point1(), segment.point2());
Expand All @@ -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,
},
Dir2,
};

#[test]
Expand Down Expand Up @@ -320,31 +322,22 @@ mod tests {
fn line() {
let translation = Vec2::new(2.0, 1.0);

let aabb1 = Line2d {
direction: Direction2d::Y,
}
.aabb_2d(translation, 0.0);
let aabb1 = Line2d { direction: Dir2::Y }.aabb_2d(translation, 0.0);
assert_eq!(aabb1.min, Vec2::new(2.0, -f32::MAX / 2.0));
assert_eq!(aabb1.max, Vec2::new(2.0, f32::MAX / 2.0));

let aabb2 = Line2d {
direction: Direction2d::X,
}
.aabb_2d(translation, 0.0);
let aabb2 = Line2d { direction: Dir2::X }.aabb_2d(translation, 0.0);
assert_eq!(aabb2.min, Vec2::new(-f32::MAX / 2.0, 1.0));
assert_eq!(aabb2.max, Vec2::new(f32::MAX / 2.0, 1.0));

let aabb3 = Line2d {
direction: Direction2d::from_xy(1.0, 1.0).unwrap(),
direction: Dir2::from_xy(1.0, 1.0).unwrap(),
}
.aabb_2d(translation, 0.0);
assert_eq!(aabb3.min, Vec2::new(-f32::MAX / 2.0, -f32::MAX / 2.0));
assert_eq!(aabb3.max, Vec2::new(f32::MAX / 2.0, f32::MAX / 2.0));

let bounding_circle = Line2d {
direction: Direction2d::Y,
}
.bounding_circle(translation, 0.0);
let bounding_circle = Line2d { direction: Dir2::Y }.bounding_circle(translation, 0.0);
assert_eq!(bounding_circle.center, translation);
assert_eq!(bounding_circle.radius(), f32::MAX / 2.0);
}
Expand Down
35 changes: 13 additions & 22 deletions crates/bevy_math/src/bounding/bounded3d/primitive_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ 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,
},
Dir3,
};

use super::{Aabb3d, Bounded3d, BoundingSphere};
Expand Down Expand Up @@ -151,7 +152,7 @@ impl Bounded3d for Capsule3d {
// Get the line segment between the hemispheres of the rotated capsule
let segment = Segment3d {
// Multiplying a normalized vector (Vec3::Y) with a rotation returns a normalized vector.
direction: Direction3d::new_unchecked(rotation * Vec3::Y),
direction: Dir3::new_unchecked(rotation * Vec3::Y),
half_length: self.half_length,
};
let (a, b) = (segment.point1(), segment.point2());
Expand Down Expand Up @@ -311,9 +312,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,
},
Dir3,
};

#[test]
Expand Down Expand Up @@ -359,38 +361,27 @@ mod tests {
fn line() {
let translation = Vec3::new(2.0, 1.0, 0.0);

let aabb1 = Line3d {
direction: Direction3d::Y,
}
.aabb_3d(translation, Quat::IDENTITY);
let aabb1 = Line3d { direction: Dir3::Y }.aabb_3d(translation, Quat::IDENTITY);
assert_eq!(aabb1.min, Vec3::new(2.0, -f32::MAX / 2.0, 0.0));
assert_eq!(aabb1.max, Vec3::new(2.0, f32::MAX / 2.0, 0.0));

let aabb2 = Line3d {
direction: Direction3d::X,
}
.aabb_3d(translation, Quat::IDENTITY);
let aabb2 = Line3d { direction: Dir3::X }.aabb_3d(translation, Quat::IDENTITY);
assert_eq!(aabb2.min, Vec3::new(-f32::MAX / 2.0, 1.0, 0.0));
assert_eq!(aabb2.max, Vec3::new(f32::MAX / 2.0, 1.0, 0.0));

let aabb3 = Line3d {
direction: Direction3d::Z,
}
.aabb_3d(translation, Quat::IDENTITY);
let aabb3 = Line3d { direction: Dir3::Z }.aabb_3d(translation, Quat::IDENTITY);
assert_eq!(aabb3.min, Vec3::new(2.0, 1.0, -f32::MAX / 2.0));
assert_eq!(aabb3.max, Vec3::new(2.0, 1.0, f32::MAX / 2.0));

let aabb4 = Line3d {
direction: Direction3d::from_xyz(1.0, 1.0, 1.0).unwrap(),
direction: Dir3::from_xyz(1.0, 1.0, 1.0).unwrap(),
}
.aabb_3d(translation, Quat::IDENTITY);
assert_eq!(aabb4.min, Vec3::splat(-f32::MAX / 2.0));
assert_eq!(aabb4.max, Vec3::splat(f32::MAX / 2.0));

let bounding_sphere = Line3d {
direction: Direction3d::Y,
}
.bounding_sphere(translation, Quat::IDENTITY);
let bounding_sphere =
Line3d { direction: Dir3::Y }.bounding_sphere(translation, Quat::IDENTITY);
assert_eq!(bounding_sphere.center, translation);
assert_eq!(bounding_sphere.radius(), f32::MAX / 2.0);
}
Expand Down
Loading