nannou-org / nannou

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

Drawing a path with nannou::geom::path should expose lyon's end() method on builder #933

Open andrew-goldie opened 1 year ago

andrew-goldie commented 1 year ago

Drawing a non-closed (open?) curve requires lower-level use of lyon crate just to get to the end(false) method.

use nannou::{prelude::*, lyon::{geom::euclid::Point2D, path::Path}};

let mut b = lyon::path::Path::builder();
b.begin(Point2D::new(0.0, 0.0));
b.quadratic_bezier_to(Point2D::new(50.0, 0.0), Point2D::new(100.0, 100.0));
b.end(false);
let p = b.build();
draw.path().stroke().hsva(0.0, 0.0, 1.0, 1.0).stroke_weight(self.stroke_weight).events(p.iter());

Using the convenient nannou wrapper, I can only get a closed curve (leaving the close() function out and attempting to call build() causes a panic since the set of points is considered invalid by lyon):

use nannou::{prelude::*, geom::path};

// panics
let p = path().begin(pt2(0.0, 0.0)).quadratic_bezier_to(pt2(50.0, 0), pt2(100.0, 100.0)).build();

// does not panic but produces closed curve
let p = path().begin(pt2(0.0, 0.0)).quadratic_bezier_to(pt2(50.0, 0), pt2(100.0, 100.0)).close().build();

// suggested feature request
let p = path().begin(pt2(0.0, 0.0)).quadratic_bezier_to(pt2(50.0, 0), pt2(100.0, 100.0)).end(false).build();