From bc8e2746d73b30577bc1a7eb49e22c5032c4070c Mon Sep 17 00:00:00 2001 From: Arnav Mummineni <45217840+RCoder01@users.noreply.github.com> Date: Sat, 22 Jul 2023 21:02:00 -0400 Subject: [PATCH] Add reflect impls to IRect and URect (#9191) # Objective This attempts to make the new IRect and URect structs in bevy_math more similar to the existing Rect struct. ## Solution Add reflect implementations for IRect and URect, since one already exists for Rect. --- crates/bevy_math/src/rects/irect.rs | 2 +- crates/bevy_math/src/rects/urect.rs | 2 +- crates/bevy_reflect/src/impls/rect.rs | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/bevy_math/src/rects/irect.rs b/crates/bevy_math/src/rects/irect.rs index 05498cea15..b8a1b21a79 100644 --- a/crates/bevy_math/src/rects/irect.rs +++ b/crates/bevy_math/src/rects/irect.rs @@ -9,7 +9,7 @@ use crate::{IVec2, Rect, URect}; /// methods instead, which will ensure this invariant is met, unless you already have /// the minimum and maximum corners. #[repr(C)] -#[derive(Default, Clone, Copy, Debug, PartialEq)] +#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct IRect { /// The minimum corner point of the rect. diff --git a/crates/bevy_math/src/rects/urect.rs b/crates/bevy_math/src/rects/urect.rs index 1f04882d16..fb74a6183e 100644 --- a/crates/bevy_math/src/rects/urect.rs +++ b/crates/bevy_math/src/rects/urect.rs @@ -9,7 +9,7 @@ use crate::{IRect, Rect, UVec2}; /// methods instead, which will ensure this invariant is met, unless you already have /// the minimum and maximum corners. #[repr(C)] -#[derive(Default, Clone, Copy, Debug, PartialEq)] +#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct URect { /// The minimum corner point of the rect. diff --git a/crates/bevy_reflect/src/impls/rect.rs b/crates/bevy_reflect/src/impls/rect.rs index b215a58599..8f882eab27 100644 --- a/crates/bevy_reflect/src/impls/rect.rs +++ b/crates/bevy_reflect/src/impls/rect.rs @@ -1,9 +1,18 @@ use crate as bevy_reflect; use crate::prelude::ReflectDefault; use crate::{ReflectDeserialize, ReflectSerialize}; -use bevy_math::{Rect, Vec2}; +use bevy_math::{IRect, IVec2, Rect, URect, UVec2, Vec2}; use bevy_reflect_derive::impl_reflect_struct; +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Hash, Serialize, Deserialize, Default)] + #[type_path = "bevy_math"] + struct IRect { + min: IVec2, + max: IVec2, + } +); + impl_reflect_struct!( #[reflect(Debug, PartialEq, Serialize, Deserialize, Default)] #[type_path = "bevy_math"] @@ -12,3 +21,12 @@ impl_reflect_struct!( max: Vec2, } ); + +impl_reflect_struct!( + #[reflect(Debug, PartialEq, Hash, Serialize, Deserialize, Default)] + #[type_path = "bevy_math"] + struct URect { + min: UVec2, + max: UVec2, + } +);