use crate::math::geometry::Shape;
pub const trait GetPosX<T> {
fn get_x_mut(&mut self) -> &mut T;
fn get_x(&self) -> T;
fn set_x(&mut self, value: T);
}
pub const trait GetPosY<T> {
fn get_y_mut(&mut self) -> &mut T;
fn get_y(&self) -> T;
fn set_y(&mut self, value: T);
}
pub const trait GetPosZ<T> {
fn get_z_mut(&mut self) -> &mut T;
fn get_z(&self) -> T;
fn set_z(&mut self, value: T);
}
pub const trait GetPosW<T> {
fn get_w_mut(&mut self) -> &mut T;
fn get_w(&self) -> T;
fn set_w(&mut self, value: T);
}
pub const trait Position<V, S: Shape<V>> {
fn get_shape(&self) -> &S;
fn get_shape_mut(&mut self) -> &mut S;
}
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "wincode",
derive(wincode::SchemaWrite, wincode::SchemaRead)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct Pos1D<V, S: Shape<V>> {
pub pos: V,
pub shape: S,
}
impl<V, S: Shape<V>> Pos1D<V, S> {
#[must_use]
pub const fn new(x: V, shape: S) -> Self {
Self {
pos: x,
shape,
}
}
}
impl<V: Copy, S: Shape<V>> Pos1D<V, S> {
#[must_use]
pub const fn get_pos(&self) -> V {
self.pos
}
}
impl<V: Copy, S: Shape<V>> const GetPosX<V> for Pos1D<V, S> {
fn get_x_mut(&mut self) -> &mut V {
&mut self.pos
}
fn get_x(&self) -> V {
self.pos
}
fn set_x(&mut self, value: V) {
self.pos = value;
}
}
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "wincode",
derive(wincode::SchemaWrite, wincode::SchemaRead)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct Pos2D<V, S: Shape<V>> {
pub pos: (V, V),
pub shape: S,
}
impl<V, S: Shape<V>> Pos2D<V, S> {
#[must_use]
pub const fn new(pos: (V, V), shape: S) -> Self {
Self {
pos,
shape,
}
}
}
impl<V: Copy, S: Shape<V>> Pos2D<V, S> {
#[must_use]
pub const fn get_pos(&self) -> (V, V) {
self.pos
}
}
impl<V: Copy, S: Shape<V>> const GetPosX<V> for Pos2D<V, S> {
fn get_x_mut(&mut self) -> &mut V {
&mut self.pos.0
}
fn get_x(&self) -> V {
self.pos.0
}
fn set_x(&mut self, value: V) {
self.pos.0 = value;
}
}
impl<V: Copy, S: Shape<V>> const GetPosY<V> for Pos2D<V, S> {
fn get_y_mut(&mut self) -> &mut V {
&mut self.pos.1
}
fn get_y(&self) -> V {
self.pos.1
}
fn set_y(&mut self, value: V) {
self.pos.1 = value;
}
}
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "wincode",
derive(wincode::SchemaWrite, wincode::SchemaRead)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct Pos3D<V, S: Shape<V>> {
pub pos: (V, V, V),
pub shape: S,
}
impl<V, S: Shape<V>> Pos3D<V, S> {
#[must_use]
pub const fn new(pos: (V, V, V), shape: S) -> Self {
Self {
pos,
shape,
}
}
}
impl<V: Copy, S: Shape<V>> Pos3D<V, S> {
#[must_use]
pub const fn get_pos(&self) -> (V, V, V) {
self.pos
}
}
impl<V: Copy, S: Shape<V>> const GetPosX<V> for Pos3D<V, S> {
fn get_x_mut(&mut self) -> &mut V {
&mut self.pos.0
}
fn get_x(&self) -> V {
self.pos.0
}
fn set_x(&mut self, value: V) {
self.pos.0 = value;
}
}
impl<V: Copy, S: Shape<V>> const GetPosY<V> for Pos3D<V, S> {
fn get_y_mut(&mut self) -> &mut V {
&mut self.pos.1
}
fn get_y(&self) -> V {
self.pos.1
}
fn set_y(&mut self, value: V) {
self.pos.1 = value;
}
}
impl<V: Copy, S: Shape<V>> const GetPosZ<V> for Pos3D<V, S> {
fn get_z_mut(&mut self) -> &mut V {
&mut self.pos.2
}
fn get_z(&self) -> V {
self.pos.2
}
fn set_z(&mut self, value: V) {
self.pos.2 = value;
}
}
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "wincode",
derive(wincode::SchemaWrite, wincode::SchemaRead)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct Pos4D<V, S: Shape<V>> {
pub pos: (V, V, V, V),
pub shape: S,
}
impl<V: Copy, S: Shape<V>> Pos4D<V, S> {
#[must_use]
pub const fn get_pos(&self) -> (V, V, V, V) {
self.pos
}
}
impl<V, S: Shape<V>> Pos4D<V, S> {
#[must_use]
pub const fn new(pos: (V, V, V, V), shape: S) -> Self {
Self {
pos,
shape,
}
}
}
impl<V: Copy, S: Shape<V>> const GetPosX<V> for Pos4D<V, S> {
fn get_x_mut(&mut self) -> &mut V {
&mut self.pos.0
}
fn get_x(&self) -> V {
self.pos.0
}
fn set_x(&mut self, value: V) {
self.pos.0 = value;
}
}
impl<V: Copy, S: Shape<V>> const GetPosY<V> for Pos4D<V, S> {
fn get_y_mut(&mut self) -> &mut V {
&mut self.pos.1
}
fn get_y(&self) -> V {
self.pos.1
}
fn set_y(&mut self, value: V) {
self.pos.1 = value;
}
}
impl<V: Copy, S: Shape<V>> const GetPosZ<V> for Pos4D<V, S> {
fn get_z_mut(&mut self) -> &mut V {
&mut self.pos.2
}
fn get_z(&self) -> V {
self.pos.2
}
fn set_z(&mut self, value: V) {
self.pos.2 = value;
}
}
impl<V: Copy, S: Shape<V>> const GetPosW<V> for Pos4D<V, S> {
fn get_w_mut(&mut self) -> &mut V {
&mut self.pos.3
}
fn get_w(&self) -> V {
self.pos.3
}
fn set_w(&mut self, value: V) {
self.pos.3 = value;
}
}
impl<V, S: Shape<V>> const Position<V, S> for Pos1D<V, S> {
fn get_shape(&self) -> &S {
&self.shape
}
fn get_shape_mut(&mut self) -> &mut S {
&mut self.shape
}
}
impl<V, S: Shape<V>> const Position<V, S> for Pos2D<V, S> {
fn get_shape(&self) -> &S {
&self.shape
}
fn get_shape_mut(&mut self) -> &mut S {
&mut self.shape
}
}
impl<V, S: Shape<V>> const Position<V, S> for Pos3D<V, S> {
fn get_shape(&self) -> &S {
&self.shape
}
fn get_shape_mut(&mut self) -> &mut S {
&mut self.shape
}
}
impl<V, S: Shape<V>> const Position<V, S> for Pos4D<V, S> {
fn get_shape(&self) -> &S {
&self.shape
}
fn get_shape_mut(&mut self) -> &mut S {
&mut self.shape
}
}