use core::ops::Index;
use core::ops::IndexMut;
use crate::States;
#[derive(Debug, Clone, Copy)]
#[derive(Default)]
pub struct Transition<S: States> {
pub to: S,
#[cfg(feature = "costs")]
pub cost: f32,
}
impl<S: States> Transition<S> {
pub const fn new(to: S) -> Self {
Self {
to,
#[cfg(feature = "costs")]
cost: 0.0,
}
}
#[cfg(feature = "costs")]
pub const fn new_with_cost(to: S, cost: f32) -> Self {
Self { to, cost }
}
#[must_use]
#[cfg(feature = "costs")]
pub const fn with_cost(mut self, cost: f32) -> Self {
self.cost = cost;
self
}
}
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct TransitionMatrix<S: States, const NS: usize, const NE: usize>([[Transition<S>; NE]; NS]);
impl<S: States, const NS: usize, const NE: usize> TransitionMatrix<S, NS, NE> {
pub const fn new(arr: [[Transition<S>; NE]; NS]) -> Self {
Self(arr)
}
}
impl<S: States, const NS: usize, const NE: usize> Index<usize> for TransitionMatrix<S, NS, NE> {
type Output = [Transition<S>; NE];
fn index(&self, index: usize) -> &Self::Output {
&self.0[index]
}
}
impl<S: States, const NS: usize, const NE: usize> IndexMut<usize> for TransitionMatrix<S, NS, NE> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.0[index]
}
}