Expand description
Core infrastructure for evaluating complex closed-form implicit surfaces.
use fidget_core::{
context::Context,
shape::EzShape,
vm::VmShape
};
let mut ctx = Context::new();
let x = ctx.x();
let y = ctx.y();
let x_squared = ctx.mul(x, x)?;
let y_squared = ctx.mul(y, y)?;
let radius = ctx.add(x_squared, y_squared)?;
let circle = ctx.sub(radius, 1.0)?;
let shape = VmShape::new(&ctx, circle)?;
let mut eval = VmShape::new_point_eval();
let tape = shape.ez_point_tape();
let (v, _trace) = eval.eval(&tape, 0.0, 0.0, 0.0)?;
assert_eq!(v, -1.0);
let (v, _trace) = eval.eval(&tape, 1.0, 0.0, 0.0)?;
assert_eq!(v, 0.0);
const N: usize = 15;
for i in 0..N {
for j in 0..N {
let x = (i as f32 + 0.5) / (N as f32 / 2.0) - 1.0;
let y = (j as f32 + 0.5) / (N as f32 / 2.0) - 1.0;
let (v, _trace) = eval.eval(&tape, x, y, 0.0)?;
print!("{}", if v < 0.0 { "##" } else { " " });
}
println!();
}
// This will print
// ##########
// ##################
// ######################
// ##########################
// ##########################
// ##############################
// ##############################
// ##############################
// ##############################
// ##############################
// ##########################
// ##########################
// ######################
// ##################
// ##########
Re-exports§
pub use context::Context;
Modules§
- compiler
- Compiler infrastructure
- context
- Infrastructure for representing math expressions as trees and graphs
- eval
- Traits and data structures for function evaluation
- render
- Common types for all kinds of rendering
- shape
- Data structures for shape evaluation
- types
- Custom types used during evaluation
- var
- Input variables to math expressions
- vm
- Simple virtual machine for shape evaluation
Enums§
- Error
- Universal error type for Fidget