use crate::components::Cell;
use bevy::prelude::{Component, IVec3};
use std::ops::Deref;
const NEIGHBOR_COORDINATES: [IVec3; 6] = [
IVec3::new(0, 0, -1),
IVec3::new(-1, 0, 0),
IVec3::new(0, 1, 0),
IVec3::new(1, 0, 0),
IVec3::new(0, -1, 0),
IVec3::new(0, 0, 1),
];
#[derive(Debug, Clone, Component)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub struct NeumannCell3d {
pub coords: IVec3,
}
impl Deref for NeumannCell3d {
type Target = IVec3;
fn deref(&self) -> &Self::Target {
&self.coords
}
}
impl Cell for NeumannCell3d {
type Coordinates = IVec3;
#[inline]
fn coords(&self) -> &Self::Coordinates {
&self.coords
}
#[inline]
fn neighbor_coordinates(&self) -> impl ExactSizeIterator<Item = Self::Coordinates> + '_ {
NEIGHBOR_COORDINATES.map(|c| c + *self.coords()).into_iter()
}
}
impl NeumannCell3d {
#[must_use]
#[inline]
pub const fn new(coords: IVec3) -> Self {
Self { coords }
}
}