#![warn(missing_docs)]
pub mod context;
pub use context::Context;
pub mod compiler;
pub mod eval;
pub mod render;
pub mod shape;
pub mod types;
pub mod var;
pub mod vm;
mod error;
pub use error::Error;
#[cfg(test)]
mod test {
use crate::Error;
use crate::context::*;
use crate::var::Var;
#[test]
fn it_works() {
let mut ctx = Context::new();
let x1 = ctx.x();
let x2 = ctx.x();
assert_eq!(x1, x2);
let a = ctx.constant(1.0);
let b = ctx.constant(1.0);
assert_eq!(a, b);
assert_eq!(ctx.get_const(a).unwrap(), 1.0);
assert!(matches!(ctx.get_const(x1), Err(Error::NotAConst)));
let c = ctx.add(a, b).unwrap();
assert_eq!(ctx.get_const(c).unwrap(), 2.0);
let c = ctx.neg(c).unwrap();
assert_eq!(ctx.get_const(c).unwrap(), -2.0);
}
#[test]
fn test_constant_folding() {
let mut ctx = Context::new();
let a = ctx.constant(1.0);
assert_eq!(ctx.len(), 1);
let b = ctx.constant(-1.0);
assert_eq!(ctx.len(), 2);
let _ = ctx.add(a, b);
assert_eq!(ctx.len(), 3);
let _ = ctx.add(a, b);
assert_eq!(ctx.len(), 3);
let _ = ctx.mul(a, b);
assert_eq!(ctx.len(), 3);
}
#[test]
fn test_eval() {
let mut ctx = Context::new();
let x = ctx.x();
let y = ctx.y();
let v = ctx.add(x, y).unwrap();
assert_eq!(
ctx.eval(v, &[(Var::X, 1.0), (Var::Y, 2.0)].into_iter().collect())
.unwrap(),
3.0
);
assert_eq!(ctx.eval_xyz(v, 2.0, 3.0, 0.0).unwrap(), 5.0);
}
}