mod determinant;
mod transpose;
mod identity;
mod invert;
mod get_minors;
mod sqrt;
mod sin;
mod cos;
mod exit;
mod cross;
mod dot;
mod linspace;
mod plot;
mod rotation;
use std::{
collections::HashMap,
rc::Rc,
};
use crate::Matrix;
use crate::error::*;
pub use determinant::Determinant;
pub use transpose::Transpose;
pub use identity::Identity;
pub use invert::Invert;
pub use get_minors::GetMinors;
pub use sqrt::Sqrt;
pub use sin::Sin;
pub use cos::Cos;
pub use exit::Exit;
pub use cross::Cross;
pub use dot::Dot;
pub use linspace::Linspace;
pub use plot::Plt;
pub use rotation::Rotation2d;
pub trait StdFunc {
fn eval(&self, args: Vec<Matrix>) -> Matrix;
}
pub struct Error;
impl StdFunc for Error {
fn eval(&self, _args: Vec<Matrix>) -> Matrix {
Matrix::new(0, 0, Vec::new())
}
}
pub fn get_std_function(name: String) -> Rc<dyn StdFunc> {
let mut hashmap: HashMap<String, Rc<dyn StdFunc>> = HashMap::new();
hashmap.insert("t".to_string(), Rc::new(Transpose {}));
hashmap.insert("det".to_string(), Rc::new(Determinant {}));
hashmap.insert("I".to_string(), Rc::new(Identity {}));
hashmap.insert("inv".to_string(), Rc::new(Invert {}));
hashmap.insert("sqrt".to_string(), Rc::new(Sqrt {}));
hashmap.insert("sin".to_string(), Rc::new(Sin {}));
hashmap.insert("cos".to_string(), Rc::new(Cos {}));
hashmap.insert("exit".to_string(), Rc::new(Exit {}));
hashmap.insert("cross".to_string(), Rc::new(Cross {}));
hashmap.insert("dot".to_string(), Rc::new(Dot {}));
hashmap.insert("linspace".to_string(), Rc::new(Linspace {}));
hashmap.insert("plot".to_string(), Rc::new(Plt {}));
hashmap.insert("rot2".to_string(), Rc::new(Rotation2d {}));
match hashmap.get(&name) {
Some(f) => f.clone(),
None => {
throw(CouldNotFindFunction);
Rc::new(Error {})
},
}
}