-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Move bevy_math
Reflect
impls
#13520
Move bevy_math
Reflect
impls
#13520
Changes from 8 commits
2970bc0
b27640b
d932088
84986ca
a986370
da43104
4f480ed
82849ae
30ccc9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ use crate::{ | |
Quat, Rotation2d, Vec2, Vec3, Vec3A, | ||
}; | ||
|
||
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] | ||
use bevy_reflect::prelude::*; | ||
|
||
/// An error indicating that a direction is invalid. | ||
#[derive(Debug, PartialEq)] | ||
pub enum InvalidDirectionError { | ||
|
@@ -79,6 +82,15 @@ 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(bevy_reflect::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 +281,15 @@ 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(bevy_reflect::Reflect), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We can avoid the #[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
#[cfg(all(feature = "bevy_reflect", feature = "serialize"))]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; This isn't mandatory, but since we'll probably need to add a separate import for |
||
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 +491,15 @@ 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(bevy_reflect::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 {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,21 @@ use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, PI}; | |
use super::{Measured2d, Primitive2d, WindingOrder}; | ||
use crate::{Dir2, Vec2}; | ||
|
||
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] | ||
use bevy_reflect::prelude::*; | ||
|
||
/// A circle primitive | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] | ||
#[cfg_attr( | ||
feature = "bevy_reflect", | ||
derive(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these types also implement 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 +715,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +865,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +962,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +1098,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +1139,15 @@ 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(bevy_reflect::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 +1158,15 @@ 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(bevy_reflect::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 +1222,11 @@ 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(bevy_reflect::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 +1283,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +1454,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +1547,11 @@ 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(bevy_reflect::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 +1608,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[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 +1754,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(bevy_reflect::Reflect), | ||
reflect(Debug, PartialEq) | ||
)] | ||
#[cfg_attr( | ||
all(feature = "serialize", feature = "bevy_reflect"), | ||
reflect(Serialize, Deserialize) | ||
)] | ||
#[doc(alias = "stadium", alias = "pill")] | ||
pub struct Capsule2d { | ||
/// The radius of the capsule | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could we avoid glob importing here? The
serialize
feature really only applies toReflectSerialize
andReflectDeserialize
. Other items, likeReflect
andReflectDefault
, don't require that feature. I think specifying the items manually clarifies why this particular feature gate is used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure, I'll go ahead and update it along with your other suggestions, they are all valid concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!