Skip to content

v0.2.4

Pre-release
Pre-release
Compare
Choose a tag to compare
@mkeeter mkeeter released this 11 Apr 12:17
· 147 commits to main since this release
11c49a4

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 parent Context (and therefore without deduplication); the resulting trees can be loaded into a Context using Context::import. This replaces the BoundNode and BoundContext types (previously only available for unit tests).
  • Remove Context::remap_xyz in favor of lazy remapping with Tree::remap_xyz.
  • Use Tree in Rhai scripts, removing the per-script Context. This is an API change: previously, shapes in Rhai were thunks evaluated during calls to draw(..); now, shapes in Rhai are Tree 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.