add error handling
This commit is contained in:
parent
5470a9b78a
commit
42773aa2a2
@ -9,7 +9,8 @@ pub type LJResult<T> = Result<T, Box<dyn std::error::Error>>;
|
|||||||
pub enum LJError {
|
pub enum LJError {
|
||||||
Config(ConfigError),
|
Config(ConfigError),
|
||||||
RedisConnect(RedisError),
|
RedisConnect(RedisError),
|
||||||
HeliosDeviceMissing
|
HeliosDeviceMissing,
|
||||||
|
BadEDH
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for LJError {
|
impl fmt::Display for LJError {
|
||||||
@ -26,6 +27,9 @@ impl fmt::Display for LJError {
|
|||||||
},
|
},
|
||||||
HeliosDeviceMissing => {
|
HeliosDeviceMissing => {
|
||||||
write!(f, "helios device not found")
|
write!(f, "helios device not found")
|
||||||
|
},
|
||||||
|
BadEDH => {
|
||||||
|
write!(f, "EDH matrix is not a 3x3 matrix")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
use crate::point::Color;
|
use crate::point::Color;
|
||||||
use nalgebra::base::Matrix3;
|
use nalgebra::base::Matrix3;
|
||||||
use crate::errors::LJResult;
|
use crate::errors::{LJError,LJResult};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct EDH {
|
pub struct EDH {
|
||||||
pub matrix: Matrix3<f32>
|
pub matrix: Matrix3<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl EDH {
|
impl EDH {
|
||||||
pub fn new(vec: Vec<Vec<f32>>) -> LJResult<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],
|
let matrix = Matrix3::new(vec[0][0], vec[0][1], vec[0][2],
|
||||||
vec[1][0], vec[1][1], vec[1][2],
|
vec[1][0], vec[1][1], vec[1][2],
|
||||||
vec[2][0], vec[2][1], vec[2][2]);
|
vec[2][0], vec[2][1], vec[2][2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user