Implement Serialize/Deserialize/PartialEq for bounding primitives (#18281)
# Objective Probably just because of an oversight, bounding primitives like `Aabb3d` did not implement `Serialize`/`Deserialize` with the `serialize` feature enabled, so the goal of this PR is to fill the gap. ## Solution Derive it conditionally, just like we do for everything else. Also added in `PartialEq`, just because I touched the files. ## Testing Compiled with different feature combinations.
This commit is contained in:
parent
dc7cb2a3e1
commit
84463e60e1
@ -9,6 +9,10 @@ use crate::{
|
||||
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy_reflect::Reflect;
|
||||
#[cfg(all(feature = "bevy_reflect", feature = "serialize"))]
|
||||
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||
#[cfg(feature = "serialize")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Computes the geometric center of the given set of points.
|
||||
#[inline(always)]
|
||||
@ -32,8 +36,13 @@ pub trait Bounded2d {
|
||||
|
||||
/// A 2D axis-aligned bounding box, or bounding rectangle
|
||||
#[doc(alias = "BoundingRectangle")]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize), derive(Deserialize))]
|
||||
#[cfg_attr(
|
||||
all(feature = "serialize", feature = "bevy_reflect"),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Aabb2d {
|
||||
/// The minimum, conventionally bottom-left, point of the box
|
||||
pub min: Vec2,
|
||||
@ -450,8 +459,13 @@ mod aabb2d_tests {
|
||||
use crate::primitives::Circle;
|
||||
|
||||
/// A bounding circle
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize), derive(Deserialize))]
|
||||
#[cfg_attr(
|
||||
all(feature = "serialize", feature = "bevy_reflect"),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct BoundingCircle {
|
||||
/// The center of the bounding circle
|
||||
pub center: Vec2,
|
||||
|
||||
@ -11,6 +11,11 @@ use crate::{
|
||||
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy_reflect::Reflect;
|
||||
#[cfg(all(feature = "bevy_reflect", feature = "serialize"))]
|
||||
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||
#[cfg(feature = "serialize")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use extrusion::BoundedExtrusion;
|
||||
|
||||
/// Computes the geometric center of the given set of points.
|
||||
@ -36,8 +41,13 @@ pub trait Bounded3d {
|
||||
}
|
||||
|
||||
/// A 3D axis-aligned bounding box
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize), derive(Deserialize))]
|
||||
#[cfg_attr(
|
||||
all(feature = "serialize", feature = "bevy_reflect"),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Aabb3d {
|
||||
/// The minimum point of the box
|
||||
pub min: Vec3A,
|
||||
@ -456,8 +466,13 @@ mod aabb3d_tests {
|
||||
use crate::primitives::Sphere;
|
||||
|
||||
/// A bounding sphere
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize), derive(Deserialize))]
|
||||
#[cfg_attr(
|
||||
all(feature = "serialize", feature = "bevy_reflect"),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct BoundingSphere {
|
||||
/// The center of the bounding sphere
|
||||
pub center: Vec3A,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user