#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[repr(C)]
#[derive(Default, Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Quaternion {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
impl Quaternion {
#[inline]
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
Self { x, y, z, w }
}
}
impl From<crate::Vector4> for Quaternion {
#[inline]
fn from(v: crate::Vector4) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
w: v.w,
}
}
}
impl From<Quaternion> for crate::Vector4 {
#[inline]
fn from(q: Quaternion) -> Self {
crate::Vector4 {
x: q.x,
y: q.y,
z: q.z,
w: q.w,
}
}
}
#[repr(C)]
#[derive(Default, Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rectangle {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}
impl Rectangle {
#[must_use]
pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
Self {
x,
y,
width,
height,
}
}
#[inline]
#[must_use]
pub fn check_collision_recs(&self, other: Rectangle) -> bool {
unsafe { crate::CheckCollisionRecs(*self, other) }
}
#[inline]
#[must_use]
pub fn check_collision_circle_rec(
&self,
center: impl Into<crate::Vector2>,
radius: f32,
) -> bool {
unsafe { crate::CheckCollisionCircleRec(center.into(), radius, *self) }
}
#[inline]
#[must_use]
pub fn get_collision_rec(&self, other: Rectangle) -> Option<Rectangle> {
self.check_collision_recs(other).then(|| {
unsafe { crate::GetCollisionRec(*self, other) }
})
}
#[inline]
#[must_use]
pub fn check_collision_point_rec(&self, point: impl Into<crate::Vector2>) -> bool {
unsafe { crate::CheckCollisionPointRec(point.into(), *self) }
}
}