add error handling

This commit is contained in:
Marc Planard 2023-07-01 14:44:51 +02:00
parent 5470a9b78a
commit 42773aa2a2
2 changed files with 13 additions and 3 deletions

View File

@ -9,7 +9,8 @@ pub type LJResult<T> = Result<T, Box<dyn std::error::Error>>;
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")
}
}
}

View File

@ -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<f32>
}
impl EDH {
pub fn new(vec: Vec<Vec<f32>>) -> LJResult<EDH> {
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]);