nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.05k stars 307 forks source link

Implement nannou::geom::path::Builder `end` method #908

Closed Swiddis closed 3 weeks ago

Swiddis commented 1 year ago

The nannou::geom::path::Builder doesn't expose the internal lyon::path::path::Builder's end method, which leads to validation panics when a path is built outside of release mode. Reproducable example (must be run without --release, Lyon's path validator is turned off if the flag is enabled):

use nannou::prelude::*;
use nannou::geom::path;

fn main() {
    let mut builder = path();
    builder = builder.begin(vec2(-50.0, 0.0));
    builder = builder.quadratic_bezier_to(vec2(0.0, 25.0), vec2(50.0, 0.0));
    let _path = builder.build();
}

Since Lyon's Builder::end isn't exposed by Nannou, the only clearly documented way out is with close, but that's undesirable as it forces a closed loop. A workaround for this is to use path.inner_mut().end(false);, but for convenience this PR adds it to the Builder directly.

Requiring paths to be properly ended before build was added in Lyon v0.17. I see that an end method was correctly added with the version bump, but it wasn't published.

Resolves #933