-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Derive PartialEq, Serialize, Deserialize and Reflect on primitives
- Loading branch information
Showing
5 changed files
with
274 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use crate as bevy_reflect; | ||
use crate::{ReflectDeserialize, ReflectSerialize}; | ||
use bevy_math::{primitives::*, Vec2}; | ||
use bevy_reflect_derive::{impl_reflect_struct, impl_reflect_value}; | ||
|
||
impl_reflect_value!(::bevy_math::primitives::Direction2d( | ||
Debug, | ||
PartialEq, | ||
Serialize, | ||
Deserialize | ||
)); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Circle { | ||
radius: f32, | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Ellipse { | ||
pub half_size: Vec2, | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Plane2d { | ||
normal: Direction2d, | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Line2d { | ||
direction: Direction2d, | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Segment2d { | ||
direction: Direction2d, | ||
half_length: f32, | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Polyline2d<const N: usize> { | ||
vertices: [Vec2; N], | ||
} | ||
); | ||
|
||
// impl_reflect_struct!( | ||
// #[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
// #[type_path = "bevy_math::primitives"] | ||
// struct BoxedPolyline2d { | ||
// vertices: Box<[Vec2]>, | ||
// } | ||
// ); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Triangle2d { | ||
vertices: [Vec2; 3], | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Rectangle { | ||
half_size: Vec2, | ||
} | ||
); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct Polygon<const N: usize> { | ||
vertices: [Vec2; N], | ||
} | ||
); | ||
|
||
// impl_reflect_struct!( | ||
// #[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
// #[type_path = "bevy_math::primitives"] | ||
// struct BoxedPolygon { | ||
// vertices: Box<[Vec2]>, | ||
// } | ||
// ); | ||
|
||
impl_reflect_struct!( | ||
#[reflect(Debug, PartialEq, Serialize, Deserialize)] | ||
#[type_path = "bevy_math::primitives"] | ||
struct RegularPolygon { | ||
circumcircle: Circle, | ||
sides: usize, | ||
} | ||
); |
Oops, something went wrong.