diff --git a/src/errors.rs b/src/errors.rs index ff40f33..1173dbe 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -9,7 +9,8 @@ pub type LJResult = Result>; pub enum LJError { Config(ConfigError), RedisConnect(RedisError), - HeliosDeviceMissing + HeliosDeviceMissing, + BadEDH } impl fmt::Display for LJError { @@ -26,6 +27,9 @@ impl fmt::Display for LJError { }, HeliosDeviceMissing => { write!(f, "helios device not found") + }, + BadEDH => { + write!(f, "EDH matrix is not a 3x3 matrix") } } } diff --git a/src/worldstate.rs b/src/worldstate.rs index 38b1bd0..d51536b 100644 --- a/src/worldstate.rs +++ b/src/worldstate.rs @@ -1,14 +1,20 @@ use crate::point::Color; use nalgebra::base::Matrix3; -use crate::errors::LJResult; +use crate::errors::{LJError,LJResult}; + #[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)); + } let matrix = Matrix3::new(vec[0][0], vec[0][1], vec[0][2], vec[1][0], vec[1][1], vec[1][2], vec[2][0], vec[2][1], vec[2][2]);