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.
This commit is contained in:
Olle Lukowski 2024-05-27 16:15:22 +02:00 committed by GitHub
parent cf4baf8fbf
commit 8c7f73ab81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 305 additions and 393 deletions

View file

@ -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"]

View file

@ -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<P: VectorSpace> {
/// The control points of the Bezier curve
pub control_points: Vec<[P; 4]>,
@ -114,6 +118,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicBezier<P> {
/// let positions: Vec<_> = hermite.iter_positions(100).collect();
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
pub struct CubicHermite<P: VectorSpace> {
/// The control points of the Hermite curve
pub control_points: Vec<(P, P)>,
@ -182,6 +187,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicHermite<P> {
/// let positions: Vec<_> = cardinal.iter_positions(100).collect();
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
pub struct CubicCardinalSpline<P: VectorSpace> {
/// Tension
pub tension: f32,
@ -272,6 +278,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicCardinalSpline<P> {
/// let positions: Vec<_> = b_spline.iter_positions(100).collect();
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
pub struct CubicBSpline<P: VectorSpace> {
/// The control points of the spline
pub control_points: Vec<P>,
@ -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<P: VectorSpace> {
/// The control points of the NURBS
pub control_points: Vec<P>,
@ -640,6 +648,7 @@ pub trait CubicGenerator<P: VectorSpace> {
///
/// 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<P: VectorSpace> {
/// Coefficients of the segment
pub coeff: [P; 4],
@ -799,6 +808,7 @@ impl CubicSegment<Vec2> {
/// 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<P: VectorSpace> {
/// Segments of the curve
pub segments: Vec<CubicSegment<P>>,
@ -932,6 +942,7 @@ pub trait RationalGenerator<P: VectorSpace> {
///
/// 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<P: VectorSpace> {
/// The coefficients matrix of the cubic curve.
pub coeff: [P; 4],
@ -1059,6 +1070,7 @@ impl<P: VectorSpace> RationalSegment<P> {
/// 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<P: VectorSpace> {
/// The segments in the curve
pub segments: Vec<RationalSegment<P>>,

View file

@ -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 {}

View file

@ -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<const N: usize> {
/// 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<const N: usize> {
/// 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

View file

@ -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<const N: usize> {
/// 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],

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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.
///

View file

@ -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" }

View file

@ -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<P: VectorSpace> {
control_points: Vec<[P; 4]>,
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct CubicHermite<P: VectorSpace> {
control_points: Vec<(P, P)>,
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct CubicCardinalSpline<P: VectorSpace> {
tension: f32,
control_points: Vec<P>,
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct CubicBSpline<P: VectorSpace> {
control_points: Vec<P>,
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct CubicNurbs<P: VectorSpace> {
control_points: Vec<P>,
weights: Vec<f32>,
knots: Vec<f32>,
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct LinearSpline<P: VectorSpace> {
points: Vec<P>,
}
);
impl_reflect!(
#[reflect(Debug, Default)]
#[type_path = "bevy_math::cubic_splines"]
struct CubicSegment<P: VectorSpace> {
coeff: [P; 4],
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct CubicCurve<P: VectorSpace> {
segments: Vec<CubicSegment<P>>,
}
);
impl_reflect!(
#[reflect(Debug, Default)]
#[type_path = "bevy_math::cubic_splines"]
struct RationalSegment<P: VectorSpace> {
coeff: [P; 4],
weight_coeff: [f32; 4],
knot_span: f32,
}
);
impl_reflect!(
#[reflect(Debug)]
#[type_path = "bevy_math::cubic_splines"]
struct RationalCurve<P: VectorSpace> {
segments: Vec<RationalSegment<P>>,
}
);

View file

@ -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));

View file

@ -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<const N: usize> {
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<const N: usize> {
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,
}
);

View file

@ -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<const N: usize> {
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],
}
);

View file

@ -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,
}
);

View file

@ -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,
}
);

View file

@ -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")]