v0.2.4
Pre-release
Pre-release
The highlight of this release is a refactoring of how shapes are handled in Rhai scripts: instead of being built from thunks (unevaluated closures) and evaluated in draw(..)
and draw_rgb(..)
, they are built directly using a new Tree
object. This makes writing scripts more ergonomic:
// Before
fn circle(cx, cy, r) {
|x, y| {
sqrt((x - cx) * (x - cx) +
(y - cy) * (y - cy)) - r
}
}
// After
fn circle(cx, cy, r) {
let ax = axes();
sqrt((ax.x - cx) * (ax.x - cx) +
(ax.y - cy) * (ax.y - cy)) - r
}
The change is even more noticeable on higher-level functions (functions which operate on shapes):
// Before
fn intersection(a, b) {
|x, y| {
max(a.call(x, y), b.call(x, y))
}
}
// After
fn intersection(a, b) {
a.max(b)
}
Detailed changelog
- Add helper function
Context::if_nonzero_else
to build conditionals (using the logical operators added in version 0.2.3) - Add
fidget::context::{Tree, TreeOp}
. These types allow construction of math trees without a parentContext
(and therefore without deduplication); the resulting trees can be loaded into aContext
usingContext::import
. This replaces theBoundNode
andBoundContext
types (previously only available for unit tests). - Remove
Context::remap_xyz
in favor of lazy remapping withTree::remap_xyz
. - Use
Tree
in Rhai scripts, removing the per-scriptContext
. This is an API change: previously, shapes in Rhai were thunks evaluated during calls todraw(..)
; now, shapes in Rhai areTree
objects, and there's much less function wrangling required. - Remove the distinction between variables and inputs (by removing all
Var
-related functions and opcodes). This was over-engineered; the plan going forward will be to support functions with N inputs (currently fixed to 3,x
/y
/z
). - Improved robustness of
viewer
application when editors move files instead of writing to them directly. - Add Rhai bindings for all new opcodes
- Tweak JIT calling convention to take an array of inputs instead of X, Y, Z arguments.