use bevy::prelude::*;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Reflect)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
#[reflect(Debug, Hash, PartialEq)]
pub struct PackedFeatureId(pub u32);
impl PackedFeatureId {
pub const UNKNOWN: Self = Self(0);
const CODE_MASK: u32 = 0x3fff_ffff;
const HEADER_MASK: u32 = !Self::CODE_MASK;
const HEADER_VERTEX: u32 = 0b01 << 30;
#[cfg(feature = "3d")]
const HEADER_EDGE: u32 = 0b10 << 30;
const HEADER_FACE: u32 = 0b11 << 30;
pub fn vertex(code: u32) -> Self {
assert_eq!(code & Self::HEADER_MASK, 0);
Self(Self::HEADER_VERTEX | code)
}
#[cfg(feature = "3d")]
pub fn edge(code: u32) -> Self {
assert_eq!(code & Self::HEADER_MASK, 0);
Self(Self::HEADER_EDGE | code)
}
pub fn face(code: u32) -> Self {
assert_eq!(code & Self::HEADER_MASK, 0);
Self(Self::HEADER_FACE | code)
}
pub fn is_face(self) -> bool {
self.0 & Self::HEADER_MASK == Self::HEADER_FACE
}
pub fn is_vertex(self) -> bool {
self.0 & Self::HEADER_MASK == Self::HEADER_VERTEX
}
#[cfg(feature = "3d")]
pub fn is_edge(self) -> bool {
self.0 & Self::HEADER_MASK == Self::HEADER_EDGE
}
pub fn is_unknown(self) -> bool {
self == Self::UNKNOWN
}
}
impl From<u32> for PackedFeatureId {
fn from(code: u32) -> Self {
Self(code)
}
}
#[cfg(any(feature = "parry-f32", feature = "parry-f64"))]
impl From<crate::parry::shape::PackedFeatureId> for PackedFeatureId {
fn from(id: crate::parry::shape::PackedFeatureId) -> Self {
Self(id.0)
}
}