use crate::point::{Point, Color}; use nalgebra::base::{Matrix3, Matrix1x3}; use crate::errors::{LJError, LJResult}; use log::debug; use crate::redis_ctrl::Resampler; #[derive(Debug, Default)] pub struct EDH { pub matrix: Matrix3, } impl EDH { pub fn new(vec: Vec>) -> LJResult { if vec.len() != 3 || vec[0].len() != 3 || vec[1].len() != 3 || vec[2].len() != 3 { return Err(Box::new(LJError::BadEDH)); } // this is the matrix already transposed. let matrix = Matrix3::new(vec[0][0], vec[1][0], vec[2][0], vec[0][1], vec[1][1], vec[2][1], vec[0][2], vec[1][2], vec[2][2]); Ok(EDH { matrix }) } pub fn apply(&self, point: &Point) -> Point { let p = Matrix1x3::new(point.x, point.y, 1.0); let p = p * self.matrix; let new_p = Point { x: p[0] / p[2], y: p[1] / p[2], ..*point }; debug!("{:?} => {:?}", point, new_p); new_p } } #[derive(Debug, Default)] pub struct WorldState { pub edh: EDH, pub resampler: Resampler, pub client_key: String, pub intensity: u8, pub kpps: u32, pub color: Color, pub draw_black: bool, pub draw_grid: bool, pub grid: Vec, pub color_balance: Color, } impl WorldState {}