From 8c7f73ab8132b7d38da13e42b62793baa4ada553 Mon Sep 17 00:00:00 2001 From: Olle Lukowski <63189113+Olle-Lukowski@users.noreply.github.com> Date: Mon, 27 May 2024 16:15:22 +0200 Subject: [PATCH] Move `bevy_math` `Reflect` impls (#13520) # Objective Fixes #13456 ## Solution Moved `bevy_math`'s `Reflect` impls from `bevy_reflect` to `bevy_math`. ### Quick note I accidentally used the same commit message while resolving a merge conflict (first time I had to resolve a conflict). Sorry about that. --- crates/bevy_math/Cargo.toml | 4 +- crates/bevy_math/src/cubic_splines.rs | 12 ++ crates/bevy_math/src/direction.rs | 20 +++ crates/bevy_math/src/primitives/dim2.rs | 98 ++++++++++++++ crates/bevy_math/src/primitives/dim3.rs | 115 ++++++++++++++++ crates/bevy_math/src/rects/irect.rs | 14 ++ crates/bevy_math/src/rects/rect.rs | 14 ++ crates/bevy_math/src/rects/urect.rs | 14 ++ crates/bevy_math/src/rotation2d.rs | 14 ++ crates/bevy_reflect/Cargo.toml | 6 +- .../src/impls/math/cubic_splines.rs | 89 ------------- .../bevy_reflect/src/impls/math/direction.rs | 7 - .../src/impls/math/primitives2d.rs | 112 ---------------- .../src/impls/math/primitives3d.rs | 124 ------------------ crates/bevy_reflect/src/impls/math/rect.rs | 32 ----- .../bevy_reflect/src/impls/math/rotation2d.rs | 13 -- crates/bevy_reflect/src/lib.rs | 10 -- 17 files changed, 305 insertions(+), 393 deletions(-) delete mode 100644 crates/bevy_reflect/src/impls/math/cubic_splines.rs delete mode 100644 crates/bevy_reflect/src/impls/math/direction.rs delete mode 100644 crates/bevy_reflect/src/impls/math/primitives2d.rs delete mode 100644 crates/bevy_reflect/src/impls/math/primitives3d.rs delete mode 100644 crates/bevy_reflect/src/impls/math/rect.rs delete mode 100644 crates/bevy_reflect/src/impls/math/rotation2d.rs diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index b3cca0d1dc..c2039e3874 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -20,6 +20,8 @@ rand = { version = "0.8", features = [ ], default-features = false, optional = true } smallvec = { version = "1.11" } +bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", optional = true } + [dev-dependencies] approx = "0.5" # Supply rngs for examples and tests @@ -31,7 +33,7 @@ glam = { version = "0.27", features = ["approx"] } [features] -default = ["rand"] +default = ["rand", "bevy_reflect"] serialize = ["dep:serde", "glam/serde"] # Enable approx for glam types to approximate floating point equality comparisons and assertions approx = ["dep:approx", "glam/approx"] diff --git a/crates/bevy_math/src/cubic_splines.rs b/crates/bevy_math/src/cubic_splines.rs index 147a72944a..df22ca9724 100644 --- a/crates/bevy_math/src/cubic_splines.rs +++ b/crates/bevy_math/src/cubic_splines.rs @@ -6,6 +6,9 @@ use crate::{Vec2, VectorSpace}; use thiserror::Error; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; + /// A spline composed of a single cubic Bezier curve. /// /// Useful for user-drawn curves with local control, or animation easing. See @@ -41,6 +44,7 @@ use thiserror::Error; /// let positions: Vec<_> = bezier.iter_positions(100).collect(); /// ``` #[derive(Clone, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct CubicBezier { /// The control points of the Bezier curve pub control_points: Vec<[P; 4]>, @@ -114,6 +118,7 @@ impl CubicGenerator

for CubicBezier

{ /// let positions: Vec<_> = hermite.iter_positions(100).collect(); /// ``` #[derive(Clone, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct CubicHermite { /// The control points of the Hermite curve pub control_points: Vec<(P, P)>, @@ -182,6 +187,7 @@ impl CubicGenerator

for CubicHermite

{ /// let positions: Vec<_> = cardinal.iter_positions(100).collect(); /// ``` #[derive(Clone, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct CubicCardinalSpline { /// Tension pub tension: f32, @@ -272,6 +278,7 @@ impl CubicGenerator

for CubicCardinalSpline

{ /// let positions: Vec<_> = b_spline.iter_positions(100).collect(); /// ``` #[derive(Clone, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct CubicBSpline { /// The control points of the spline pub control_points: Vec

, @@ -391,6 +398,7 @@ pub enum CubicNurbsError { /// let positions: Vec<_> = nurbs.iter_positions(100).collect(); /// ``` #[derive(Clone, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct CubicNurbs { /// The control points of the NURBS pub control_points: Vec

, @@ -640,6 +648,7 @@ pub trait CubicGenerator { /// /// Segments can be chained together to form a longer compound curve. #[derive(Copy, Clone, Debug, Default, PartialEq)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, Default))] pub struct CubicSegment { /// Coefficients of the segment pub coeff: [P; 4], @@ -799,6 +808,7 @@ impl CubicSegment { /// Use any struct that implements the [`CubicGenerator`] trait to create a new curve, such as /// [`CubicBezier`]. #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct CubicCurve { /// Segments of the curve pub segments: Vec>, @@ -932,6 +942,7 @@ pub trait RationalGenerator { /// /// Segments can be chained together to form a longer compound curve. #[derive(Copy, Clone, Debug, Default, PartialEq)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, Default))] pub struct RationalSegment { /// The coefficients matrix of the cubic curve. pub coeff: [P; 4], @@ -1059,6 +1070,7 @@ impl RationalSegment

{ /// Use any struct that implements the [`RationalGenerator`] trait to create a new curve, such as /// [`CubicNurbs`], or convert [`CubicCurve`] using `into/from`. #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct RationalCurve { /// The segments in the curve pub segments: Vec>, diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index a5af98f8f4..dc2d339f9c 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -3,6 +3,11 @@ use crate::{ Quat, Rotation2d, Vec2, Vec3, Vec3A, }; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::Reflect; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// An error indicating that a direction is invalid. #[derive(Debug, PartialEq)] pub enum InvalidDirectionError { @@ -79,6 +84,11 @@ pub type Direction3d = Dir3; /// A normalized vector pointing in a direction in 2D space #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "Direction2d")] pub struct Dir2(Vec2); impl Primitive2d for Dir2 {} @@ -269,6 +279,11 @@ impl approx::UlpsEq for Dir2 { /// A normalized vector pointing in a direction in 3D space #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "Direction3d")] pub struct Dir3(Vec3); impl Primitive3d for Dir3 {} @@ -470,6 +485,11 @@ impl approx::UlpsEq for Dir3 { /// This may or may not be faster than [`Dir3`]: make sure to benchmark! #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "Direction3dA")] pub struct Dir3A(Vec3A); impl Primitive3d for Dir3A {} diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index e945d52b85..d1e7037e79 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -3,9 +3,23 @@ use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, PI}; use super::{Measured2d, Primitive2d, WindingOrder}; use crate::{Dir2, Vec2}; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// A circle primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Circle { /// The radius of the circle pub radius: f32, @@ -703,6 +717,15 @@ mod arc_tests { /// An ellipse primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Ellipse { /// Half of the width and height of the ellipse. /// @@ -844,6 +867,15 @@ impl Measured2d for Ellipse { /// A primitive shape formed by the region between two circles, also known as a ring. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "Ring")] pub struct Annulus { /// The inner circle of the annulus @@ -932,6 +964,15 @@ impl Measured2d for Annulus { /// A rhombus primitive, also known as a diamond shape. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "Diamond")] pub struct Rhombus { /// Size of the horizontal and vertical diagonals of the rhombus @@ -1059,6 +1100,15 @@ impl Measured2d for Rhombus { /// stretching infinitely far #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Plane2d { /// The normal of the plane. The plane will be placed perpendicular to this direction pub normal: Dir2, @@ -1091,6 +1141,11 @@ impl Plane2d { /// For a finite line: [`Segment2d`] #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Line2d { /// The direction of the line. The line extends infinitely in both the given direction /// and its opposite direction @@ -1101,6 +1156,11 @@ impl Primitive2d for Line2d {} /// A segment of a line along a direction in 2D space. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "LineSegment2d")] pub struct Segment2d { /// The direction of the line segment @@ -1156,6 +1216,7 @@ impl Segment2d { /// For a version without generics: [`BoxedPolyline2d`] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] pub struct Polyline2d { /// The vertices of the polyline #[cfg_attr(feature = "serialize", serde(with = "super::serde::array"))] @@ -1212,6 +1273,15 @@ impl BoxedPolyline2d { /// A triangle in 2D space #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Triangle2d { /// The vertices of the triangle pub vertices: [Vec2; 3], @@ -1374,6 +1444,15 @@ impl Measured2d for Triangle2d { /// A rectangle primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "Quad")] pub struct Rectangle { /// Half of the width and height of the rectangle @@ -1458,6 +1537,7 @@ impl Measured2d for Rectangle { /// For a version without generics: [`BoxedPolygon`] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] pub struct Polygon { /// The vertices of the `Polygon` #[cfg_attr(feature = "serialize", serde(with = "super::serde::array"))] @@ -1514,6 +1594,15 @@ impl BoxedPolygon { /// A polygon where all vertices lie on a circle, equally far apart. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct RegularPolygon { /// The circumcircle on which all vertices lie pub circumcircle: Circle, @@ -1651,6 +1740,15 @@ impl Measured2d for RegularPolygon { /// A two-dimensional capsule is defined as a neighborhood of points at a distance (radius) from a line #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[doc(alias = "stadium", alias = "pill")] pub struct Capsule2d { /// The radius of the capsule diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index a6449cc2e0..baedaef144 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -3,9 +3,23 @@ use std::f32::consts::{FRAC_PI_3, PI}; use super::{Circle, Measured2d, Measured3d, Primitive2d, Primitive3d}; use crate::{Dir3, InvalidDirectionError, Mat3, Vec2, Vec3}; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// A sphere primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Sphere { /// The radius of the sphere pub radius: f32, @@ -69,6 +83,15 @@ impl Measured3d for Sphere { /// A bounded plane in 3D space. It forms a surface starting from the origin with a defined height and width. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Plane3d { /// The normal of the plane. The plane will be placed perpendicular to this direction pub normal: Dir3, @@ -132,6 +155,15 @@ impl Plane3d { /// stretching infinitely far #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct InfinitePlane3d { /// The normal of the plane. The plane will be placed perpendicular to this direction pub normal: Dir3, @@ -189,6 +221,11 @@ impl InfinitePlane3d { /// For a finite line: [`Segment3d`] #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Line3d { /// The direction of the line pub direction: Dir3, @@ -199,6 +236,11 @@ impl Primitive3d for Line3d {} #[doc(alias = "LineSegment3d")] #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Segment3d { /// The direction of the line pub direction: Dir3, @@ -253,6 +295,7 @@ impl Segment3d { /// For a version without generics: [`BoxedPolyline3d`] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] pub struct Polyline3d { /// The vertices of the polyline #[cfg_attr(feature = "serialize", serde(with = "super::serde::array"))] @@ -309,6 +352,15 @@ impl BoxedPolyline3d { /// A cuboid primitive, more commonly known as a box. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Cuboid { /// Half of the width, height and depth of the cuboid pub half_size: Vec3, @@ -392,6 +444,15 @@ impl Measured3d for Cuboid { /// A cylinder primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Cylinder { /// The radius of the cylinder pub radius: f32, @@ -461,6 +522,15 @@ impl Measured3d for Cylinder { /// A three-dimensional capsule is defined as a surface at a distance (radius) from a line #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Capsule3d { /// The radius of the capsule pub radius: f32, @@ -520,6 +590,15 @@ impl Measured3d for Capsule3d { /// A cone primitive. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Cone { /// The radius of the base pub radius: f32, @@ -589,6 +668,15 @@ impl Measured3d for Cone { /// by slicing off a section of a cone. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct ConicalFrustum { /// The radius of the top of the frustum pub radius_top: f32, @@ -631,6 +719,15 @@ pub enum TorusKind { /// A torus primitive, often representing a ring or donut shape #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Torus { /// The radius of the tube of the torus #[doc( @@ -733,6 +830,15 @@ impl Measured3d for Torus { /// A 3D triangle primitive. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Triangle3d { /// The vertices of the triangle. pub vertices: [Vec3; 3], @@ -917,6 +1023,15 @@ impl Measured2d for Triangle3d { /// A tetrahedron primitive. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Tetrahedron { /// The vertices of the tetrahedron. pub vertices: [Vec3; 4], diff --git a/crates/bevy_math/src/rects/irect.rs b/crates/bevy_math/src/rects/irect.rs index 786f39cdd4..ae858a88c0 100644 --- a/crates/bevy_math/src/rects/irect.rs +++ b/crates/bevy_math/src/rects/irect.rs @@ -1,5 +1,10 @@ use crate::{IVec2, Rect, URect}; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// A rectangle defined by two opposite corners. /// /// The rectangle is axis aligned, and defined by its minimum and maximum coordinates, @@ -11,6 +16,15 @@ use crate::{IVec2, Rect, URect}; #[repr(C)] #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Hash, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct IRect { /// The minimum corner point of the rect. pub min: IVec2, diff --git a/crates/bevy_math/src/rects/rect.rs b/crates/bevy_math/src/rects/rect.rs index 82aa9d8574..8e804dcd08 100644 --- a/crates/bevy_math/src/rects/rect.rs +++ b/crates/bevy_math/src/rects/rect.rs @@ -1,5 +1,10 @@ use crate::{IRect, URect, Vec2}; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// A rectangle defined by two opposite corners. /// /// The rectangle is axis aligned, and defined by its minimum and maximum coordinates, @@ -11,6 +16,15 @@ use crate::{IRect, URect, Vec2}; #[repr(C)] #[derive(Default, Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Rect { /// The minimum corner point of the rect. pub min: Vec2, diff --git a/crates/bevy_math/src/rects/urect.rs b/crates/bevy_math/src/rects/urect.rs index 80fdbe7760..54cde82904 100644 --- a/crates/bevy_math/src/rects/urect.rs +++ b/crates/bevy_math/src/rects/urect.rs @@ -1,5 +1,10 @@ use crate::{IRect, Rect, UVec2}; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// A rectangle defined by two opposite corners. /// /// The rectangle is axis aligned, and defined by its minimum and maximum coordinates, @@ -11,6 +16,15 @@ use crate::{IRect, Rect, UVec2}; #[repr(C)] #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Hash, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct URect { /// The minimum corner point of the rect. pub min: UVec2, diff --git a/crates/bevy_math/src/rotation2d.rs b/crates/bevy_math/src/rotation2d.rs index bdeb5620a2..1291128fc9 100644 --- a/crates/bevy_math/src/rotation2d.rs +++ b/crates/bevy_math/src/rotation2d.rs @@ -2,6 +2,11 @@ use glam::FloatExt; use crate::prelude::{Mat2, Vec2}; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; + /// A counterclockwise 2D rotation in radians. /// /// The rotation angle is wrapped to be within the `(-pi, pi]` range. @@ -29,6 +34,15 @@ use crate::prelude::{Mat2, Vec2}; /// ``` #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, PartialEq, Default) +)] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] pub struct Rotation2d { /// The cosine of the rotation angle in radians. /// diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index f23f238765..d7276b5723 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -12,9 +12,8 @@ rust-version = "1.76.0" [features] default = ["smallvec"] # When enabled, provides Bevy-related reflection implementations -bevy = ["smallvec", "bevy_math", "smol_str"] +bevy = ["smallvec", "smol_str"] glam = ["dep:glam"] -bevy_math = ["glam", "dep:bevy_math"] petgraph = ["dep:petgraph"] smallvec = ["dep:smallvec"] uuid = ["dep:uuid"] @@ -23,9 +22,6 @@ documentation = ["bevy_reflect_derive/documentation"] [dependencies] # bevy -bevy_math = { path = "../bevy_math", version = "0.14.0-dev", features = [ - "serialize", -], optional = true } bevy_reflect_derive = { path = "derive", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_ptr = { path = "../bevy_ptr", version = "0.14.0-dev" } diff --git a/crates/bevy_reflect/src/impls/math/cubic_splines.rs b/crates/bevy_reflect/src/impls/math/cubic_splines.rs deleted file mode 100644 index 2d14f1b624..0000000000 --- a/crates/bevy_reflect/src/impls/math/cubic_splines.rs +++ /dev/null @@ -1,89 +0,0 @@ -use crate as bevy_reflect; -use bevy_math::{cubic_splines::*, VectorSpace}; -use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect_derive::impl_reflect; - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicBezier { - control_points: Vec<[P; 4]>, - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicHermite { - control_points: Vec<(P, P)>, - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicCardinalSpline { - tension: f32, - control_points: Vec

, - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicBSpline { - control_points: Vec

, - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicNurbs { - control_points: Vec

, - weights: Vec, - knots: Vec, - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct LinearSpline { - points: Vec

, - } -); - -impl_reflect!( - #[reflect(Debug, Default)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicSegment { - coeff: [P; 4], - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct CubicCurve { - segments: Vec>, - } -); - -impl_reflect!( - #[reflect(Debug, Default)] - #[type_path = "bevy_math::cubic_splines"] - struct RationalSegment { - coeff: [P; 4], - weight_coeff: [f32; 4], - knot_span: f32, - } -); - -impl_reflect!( - #[reflect(Debug)] - #[type_path = "bevy_math::cubic_splines"] - struct RationalCurve { - segments: Vec>, - } -); diff --git a/crates/bevy_reflect/src/impls/math/direction.rs b/crates/bevy_reflect/src/impls/math/direction.rs deleted file mode 100644 index abfd9ff0f8..0000000000 --- a/crates/bevy_reflect/src/impls/math/direction.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate as bevy_reflect; -use crate::{ReflectDeserialize, ReflectSerialize}; -use bevy_reflect_derive::impl_reflect_value; - -impl_reflect_value!(::bevy_math::Dir2(Debug, PartialEq, Serialize, Deserialize)); -impl_reflect_value!(::bevy_math::Dir3(Debug, PartialEq, Serialize, Deserialize)); -impl_reflect_value!(::bevy_math::Dir3A(Debug, PartialEq, Serialize, Deserialize)); diff --git a/crates/bevy_reflect/src/impls/math/primitives2d.rs b/crates/bevy_reflect/src/impls/math/primitives2d.rs deleted file mode 100644 index 2fde8883c0..0000000000 --- a/crates/bevy_reflect/src/impls/math/primitives2d.rs +++ /dev/null @@ -1,112 +0,0 @@ -use crate as bevy_reflect; -use crate::{ReflectDeserialize, ReflectSerialize}; -use bevy_math::{primitives::*, Dir2, Vec2}; -use bevy_reflect_derive::impl_reflect; - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Circle { - radius: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Ellipse { - half_size: Vec2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Annulus { - inner_circle: Circle, - outer_circle: Circle, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Rhombus { - half_diagonals: Vec2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Plane2d { - normal: Dir2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Line2d { - direction: Dir2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Segment2d { - direction: Dir2, - half_length: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq)] - #[type_path = "bevy_math::primitives"] - struct Polyline2d { - vertices: [Vec2; N], - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Triangle2d { - vertices: [Vec2; 3], - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Rectangle { - half_size: Vec2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq)] - #[type_path = "bevy_math::primitives"] - struct Polygon { - vertices: [Vec2; N], - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct RegularPolygon { - circumcircle: Circle, - sides: usize, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Capsule2d { - radius: f32, - half_length: f32, - } -); diff --git a/crates/bevy_reflect/src/impls/math/primitives3d.rs b/crates/bevy_reflect/src/impls/math/primitives3d.rs deleted file mode 100644 index 47d9ecbb60..0000000000 --- a/crates/bevy_reflect/src/impls/math/primitives3d.rs +++ /dev/null @@ -1,124 +0,0 @@ -use crate as bevy_reflect; -use crate::{ReflectDeserialize, ReflectSerialize}; -use bevy_math::{primitives::*, Dir3, Vec2, Vec3}; -use bevy_reflect_derive::impl_reflect; - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Sphere { - radius: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Plane3d { - normal: Dir3, - half_size: Vec2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct InfinitePlane3d { - normal: Dir3, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Line3d { - direction: Dir3, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Segment3d { - direction: Dir3, - half_length: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq)] - #[type_path = "bevy_math::primitives"] - struct Polyline3d { - vertices: [Vec3; N], - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Triangle3d { - vertices: [Vec3; 3], - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Cuboid { - half_size: Vec3, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Cylinder { - radius: f32, - half_height: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Capsule3d { - radius: f32, - half_length: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Cone { - radius: f32, - height: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct ConicalFrustum { - radius_top: f32, - radius_bottom: f32, - height: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Torus { - minor_radius: f32, - major_radius: f32, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math::primitives"] - struct Tetrahedron { - vertices: [Vec3; 4], - } -); diff --git a/crates/bevy_reflect/src/impls/math/rect.rs b/crates/bevy_reflect/src/impls/math/rect.rs deleted file mode 100644 index 4389e0be19..0000000000 --- a/crates/bevy_reflect/src/impls/math/rect.rs +++ /dev/null @@ -1,32 +0,0 @@ -use crate as bevy_reflect; -use crate::prelude::ReflectDefault; -use crate::{ReflectDeserialize, ReflectSerialize}; -use bevy_math::{IRect, IVec2, Rect, URect, UVec2, Vec2}; -use bevy_reflect_derive::impl_reflect; - -impl_reflect!( - #[reflect(Debug, PartialEq, Hash, Serialize, Deserialize, Default)] - #[type_path = "bevy_math"] - struct IRect { - min: IVec2, - max: IVec2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] - #[type_path = "bevy_math"] - struct Rect { - min: Vec2, - max: Vec2, - } -); - -impl_reflect!( - #[reflect(Debug, PartialEq, Hash, Serialize, Deserialize, Default)] - #[type_path = "bevy_math"] - struct URect { - min: UVec2, - max: UVec2, - } -); diff --git a/crates/bevy_reflect/src/impls/math/rotation2d.rs b/crates/bevy_reflect/src/impls/math/rotation2d.rs deleted file mode 100644 index 4082e1bff5..0000000000 --- a/crates/bevy_reflect/src/impls/math/rotation2d.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate as bevy_reflect; -use crate::{ReflectDeserialize, ReflectSerialize}; -use bevy_math::Rotation2d; -use bevy_reflect_derive::impl_reflect; - -impl_reflect!( - #[reflect(Debug, PartialEq, Serialize, Deserialize)] - #[type_path = "bevy_math"] - struct Rotation2d { - cos: f32, - sin: f32, - } -); diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index 1ba4d1a3ec..95f7b54c00 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -490,16 +490,6 @@ mod type_registry; mod impls { #[cfg(feature = "glam")] mod glam; - - #[cfg(feature = "bevy_math")] - mod math { - mod cubic_splines; - mod direction; - mod primitives2d; - mod primitives3d; - mod rect; - mod rotation2d; - } #[cfg(feature = "petgraph")] mod petgraph; #[cfg(feature = "smallvec")]