use super::two_d_array::{OffsetRows, TwoDArray};
use glam::DVec3;
#[derive(Debug, Clone)]
pub(crate) struct CoefficientsPair {
pub sa_coefs: Vec<f64>,
pub gj_coefs: Vec<f64>,
}
impl CoefficientsPair {
pub fn configure(max_order: usize) -> Self {
Self {
sa_coefs: vec![0.0; max_order + 1],
gj_coefs: vec![0.0; max_order + 1],
}
}
pub fn apply(&self, acc_hist: &TwoDArray, ncoeff: usize) -> (DVec3, DVec3) {
let acc_0 = acc_hist.get_dvec3(0);
let mut vel_sum = acc_0 * self.sa_coefs[0];
let mut pos_sum = acc_0 * self.gj_coefs[0];
for icoeff in 1..ncoeff {
let acc_i = acc_hist.get_dvec3(icoeff);
vel_sum += acc_i * self.sa_coefs[icoeff];
pos_sum += acc_i * self.gj_coefs[icoeff];
}
(vel_sum, pos_sum)
}
pub fn apply_offset(&self, acc_hist: &OffsetRows<'_>, ncoeff: usize) -> (DVec3, DVec3) {
let acc_0 = acc_hist.get_dvec3(0);
let mut vel_sum = acc_0 * self.sa_coefs[0];
let mut pos_sum = acc_0 * self.gj_coefs[0];
for icoeff in 1..ncoeff {
let acc_i = acc_hist.get_dvec3(icoeff);
vel_sum += acc_i * self.sa_coefs[icoeff];
pos_sum += acc_i * self.gj_coefs[icoeff];
}
(vel_sum, pos_sum)
}
pub fn apply_skip_first(&self, acc_hist: &TwoDArray, ncoeff: usize) -> (DVec3, DVec3) {
let acc_0 = acc_hist.get_dvec3(1); let mut vel_sum = acc_0 * self.sa_coefs[0];
let mut pos_sum = acc_0 * self.gj_coefs[0];
for icoeff in 1..ncoeff {
let acc_i = acc_hist.get_dvec3(1 + icoeff);
vel_sum += acc_i * self.sa_coefs[icoeff];
pos_sum += acc_i * self.gj_coefs[icoeff];
}
(vel_sum, pos_sum)
}
pub fn apply_offset_skip_first(
&self,
acc_hist: &OffsetRows<'_>,
ncoeff: usize,
) -> (DVec3, DVec3) {
let acc_0 = acc_hist.get_dvec3(1);
let mut vel_sum = acc_0 * self.sa_coefs[0];
let mut pos_sum = acc_0 * self.gj_coefs[0];
for icoeff in 1..ncoeff {
let acc_i = acc_hist.get_dvec3(1 + icoeff);
vel_sum += acc_i * self.sa_coefs[icoeff];
pos_sum += acc_i * self.gj_coefs[icoeff];
}
(vel_sum, pos_sum)
}
}