Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions guide/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ back to the origins.
- Move `nannou_conrod` and `nannou_timeline` into a new repository:
https://github.com/nannou-org/nannou_conrod. Both crates are deprecated in
favour of `nannou_egui`.
- Add method for validated path ending with non-closed paths.

---

Expand Down
7 changes: 7 additions & 0 deletions nannou/src/geom/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ impl Builder {
self
}

/// Closes the current sub path without resetting the position to the first position of the
/// current sub-path.
pub fn end(mut self) -> Self {
self.builder.end(false);
self
}

/// Add a quadratic bezier curve to the path.
pub fn quadratic_bezier_to(mut self, ctrl: Point2, to: Point2) -> Self {
self.builder
Expand Down
30 changes: 30 additions & 0 deletions nannou/tests/geom_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::matches;

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

#[test]
Expand All @@ -13,3 +17,29 @@ fn angle_test() {
let vector = vec2(70.7, -60.8);
assert_eq!(vector.angle(), -0.7102547457375739);
}

#[test]
fn path_builder_end_test() {
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));
builder = builder.end();
let path = builder.build();
assert!(matches!(
path.iter().last(),
Some(Event::End { close: false, .. })
));
}

#[test]
fn path_builder_close_test() {
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));
builder = builder.close();
let path = builder.build();
assert!(matches!(
path.iter().last(),
Some(Event::End { close: true, .. })
));
}