From 2795df6dc39faf009aece1f9b4f396c5158881f4 Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Thu, 9 Nov 2023 03:06:55 +0100 Subject: [PATCH] Add some derives --- crates/bevy_math/src/primitives/dim2.rs | 26 ++++++++++++++++++++++--- crates/bevy_math/src/primitives/dim3.rs | 18 +++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index 873955e8419d0..b17de862d5331 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -2,6 +2,7 @@ use super::Primitive2d; use crate::Vec2; /// A normalized vector pointing in a direction in 2D space +#[derive(Clone, Copy, Debug)] pub struct Direction2d(Vec2); impl From for Direction2d { @@ -17,13 +18,19 @@ impl Direction2d { } } +impl std::ops::Deref for Direction2d { + type Target = Vec2; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + /// An infinite half-line pointing in a direction in 2D space +#[derive(Clone, Copy, Debug)] pub struct Ray2d(pub Direction2d); -/// An alias for [Rectangle] -pub type Quad = Rectangle; - /// A circle primitive +#[derive(Clone, Copy, Debug)] pub struct Circle { /// The radius of the circle pub radius: f32, @@ -31,6 +38,7 @@ pub struct Circle { impl Primitive2d for Circle {} /// An unbounded plane in 2D space +#[derive(Clone, Copy, Debug)] pub struct Plane2d { /// The direction in which the plane points pub normal: Direction2d, @@ -39,6 +47,7 @@ impl Primitive2d for Plane2d {} /// An infinite line along a direction in 2D space. /// For a finite line: [LineSegment2d] +#[derive(Clone, Copy, Debug)] pub struct Line2d { /// The direction of the line pub direction: Direction2d, @@ -46,6 +55,7 @@ pub struct Line2d { impl Primitive2d for Line2d {} /// A section of a line along a direction in 2D space. +#[derive(Clone, Debug)] pub struct LineSegment2d { /// The direction of the line pub direction: Direction2d, @@ -58,6 +68,7 @@ impl Primitive2d for LineSegment2d {} /// A line alone a path of N vertices in 2D space. /// For a version without generics: [BoxedPolyline2d] +#[derive(Clone, Debug)] pub struct Polyline2d { /// The vertices of the polyline pub vertices: [Vec2; N], @@ -66,6 +77,7 @@ impl Primitive2d for Polyline2d {} /// A line alone a path of vertices in 2D space. /// For a version without alloc: [Polyline2d] +#[derive(Clone, Debug)] pub struct BoxedPolyline2d { /// The vertices of the polyline pub vertices: Box<[Vec2]>, @@ -73,6 +85,7 @@ pub struct BoxedPolyline2d { impl Primitive2d for BoxedPolyline2d {} /// A triangle primitive +#[derive(Clone, Debug)] pub struct Triangle { /// The vertices of the triangle pub vertcies: [Vec2; 3], @@ -80,6 +93,7 @@ pub struct Triangle { impl Primitive2d for Triangle {} /// A rectangle primitive +#[derive(Clone, Copy, Debug)] pub struct Rectangle { /// The half width of the rectangle pub half_width: f32, @@ -88,8 +102,12 @@ pub struct Rectangle { } impl Primitive2d for Rectangle {} +/// An alias for [Rectangle] +pub type Quad = Rectangle; + /// A polygon with N vertices /// For a version without generics: [BoxedPolygon] +#[derive(Clone, Debug)] pub struct Polygon { /// The vertices of the polygon pub vertices: [Vec2; N], @@ -98,6 +116,7 @@ impl Primitive2d for Polygon {} /// A polygon with a variable number of vertices /// For a version without alloc: [Polygon] +#[derive(Clone, Debug)] pub struct BoxedPolygon { /// The vertices of the polygon pub vertices: Box<[Vec2]>, @@ -105,6 +124,7 @@ pub struct BoxedPolygon { impl Primitive2d for BoxedPolygon {} /// A polygon where all vertices lie on a circumscribed circle, equally far apart +#[derive(Clone, Copy, Debug)] pub struct RegularPolygon { /// The circumcircle on which all vertices lie pub circumcircle: Circle, diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 82125ff1e7f73..2f9d7c5331b1e 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -2,6 +2,7 @@ use super::Primitive3d; use crate::Vec3; /// A normalized vector pointing in a direction in 3D space +#[derive(Clone, Copy, Debug)] pub struct Direction3d(Vec3); impl From for Direction3d { @@ -17,10 +18,19 @@ impl Direction3d { } } +impl std::ops::Deref for Direction3d { + type Target = Vec3; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + /// An infinite half-line pointing in a direction in 3D space +#[derive(Clone, Copy, Debug)] pub struct Ray3d(pub Direction3d); /// A sphere primitive +#[derive(Clone, Copy, Debug)] pub struct Sphere { /// The radius of the sphere pub radius: f32, @@ -28,6 +38,7 @@ pub struct Sphere { impl Primitive3d for Sphere {} /// An unbounded plane in 3D space +#[derive(Clone, Copy, Debug)] pub struct Plane3d { /// The direction in which the plane points pub normal: Direction3d, @@ -36,6 +47,7 @@ impl Primitive3d for Plane3d {} /// An infinite line along a direction in 3D space. /// For a finite line: [LineSegment3d] +#[derive(Clone, Copy, Debug)] pub struct Line3d { /// The direction of the line pub direction: Direction3d, @@ -43,6 +55,7 @@ pub struct Line3d { impl Primitive3d for Line3d {} /// A section of a line along a direction in 3D space. +#[derive(Clone, Debug)] pub struct LineSegment3d { /// The direction of the line pub direction: Direction3d, @@ -55,6 +68,7 @@ impl Primitive3d for LineSegment3d {} /// A line alone a path of N vertices in 3D space. /// For a version without generics: [BoxedPolyline3d] +#[derive(Clone, Debug)] pub struct Polyline3d { /// The vertices of the polyline pub vertices: [Vec3; N], @@ -63,6 +77,7 @@ impl Primitive3d for Polyline3d {} /// A line alone a path of vertices in 3D space. /// For a version without alloc: [Polyline3d] +#[derive(Clone, Debug)] pub struct BoxedPolyline3d { /// The vertices of the polyline pub vertices: Box<[Vec3]>, @@ -70,6 +85,7 @@ pub struct BoxedPolyline3d { impl Primitive3d for BoxedPolyline3d {} /// A cuboid primitive, more commonly known as a box. +#[derive(Clone, Copy, Debug)] pub struct Cuboid { /// Half of the width, height and depth of the cuboid pub half_extents: Vec3, @@ -77,6 +93,7 @@ pub struct Cuboid { impl Primitive3d for Cuboid {} /// A cylinder primitive +#[derive(Clone, Copy, Debug)] pub struct Cylinder { /// The radius of the cylinder pub radius: f32, @@ -86,6 +103,7 @@ pub struct Cylinder { impl Primitive3d for Cylinder {} /// A capsule primitive +#[derive(Clone, Copy, Debug)] pub struct Capsule { /// The radius of the capsule pub radius: f32,