use core::ops::Mul;
use num_traits::Zero;
use vqm::{Matrix3x3Math, Matrix9x9, Matrix9x9Math, Vector3};
pub type KalmanStateVector9f32 = KalmanStateVector9<f32>;
pub type KalmanStateVector9f64 = KalmanStateVector9<f64>;
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[repr(C, align(64))]
#[allow(missing_docs)]
pub struct KalmanStateVector9<T> {
pub pos: Vector3<T>,
pub vel: Vector3<T>,
pub bias: Vector3<T>,
}
impl<T> KalmanStateVector9<T>
where
T: Copy,
{
#[inline]
pub const fn new(v: (Vector3<T>, Vector3<T>, Vector3<T>)) -> Self {
Self { pos: v.0, vel: v.1, bias: v.2 }
}
}
impl<T> From<(Vector3<T>, Vector3<T>, Vector3<T>)> for KalmanStateVector9<T> {
#[inline]
fn from(v: (Vector3<T>, Vector3<T>, Vector3<T>)) -> Self {
Self { pos: v.0, vel: v.1, bias: v.2 }
}
}
impl Mul<f32> for KalmanStateVector9<f32> {
type Output = Self;
#[inline]
fn mul(self, rhs: f32) -> Self::Output {
Self { pos: self.pos * rhs, vel: self.vel * rhs, bias: self.bias * rhs }
}
}
impl Mul<f64> for KalmanStateVector9<f64> {
type Output = Self;
#[inline]
fn mul(self, rhs: f64) -> Self::Output {
Self { pos: self.pos * rhs, vel: self.vel * rhs, bias: self.bias * rhs }
}
}
impl<T> KalmanStateVector9<T>
where
T: Copy + Zero + Matrix9x9Math + Matrix3x3Math + Mul<T, Output = T> + PartialEq,
{
#[inline]
pub fn outer_product(self, row: KalmanStateVector9<T>) -> Matrix9x9<T> {
Self::outer_product_associated(self, row)
}
#[inline]
fn outer_product_associated(col: KalmanStateVector9<T>, row: KalmanStateVector9<T>) -> Matrix9x9<T> {
let r = [row.pos.x, row.pos.y, row.pos.z, row.vel.x, row.vel.y, row.vel.z, row.bias.x, row.bias.y, row.bias.z];
let c = [col.pos.x, col.pos.y, col.pos.z, col.vel.x, col.vel.y, col.vel.z, col.bias.x, col.bias.y, col.bias.z];
let mut ret = <Matrix9x9<T>>::zero();
for (c_idx, &scalar) in r.iter().enumerate().take(9) {
let ret_col = &mut ret[c_idx * 9..(c_idx + 1) * 9];
ret_col[0] = c[0] * scalar;
ret_col[1] = c[1] * scalar;
ret_col[2] = c[2] * scalar;
ret_col[3] = c[3] * scalar;
ret_col[4] = c[4] * scalar;
ret_col[5] = c[5] * scalar;
ret_col[6] = c[6] * scalar;
ret_col[7] = c[7] * scalar;
ret_col[8] = c[8] * scalar;
}
ret
}
}
#[cfg(test)]
mod test_traits {
use super::*;
fn _is_normal<T: Sized + Send + Sync + Unpin>() {}
fn is_full<T: Sized + Send + Sync + Unpin + Copy + Clone + Default + PartialEq>() {}
#[test]
fn normal_types() {
is_full::<KalmanStateVector9f32>();
}
}