From 10db20edcfafb5af33016fe89611691b1995aaf8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 15 Oct 2024 20:08:20 +0200 Subject: [PATCH] Add `Polyline::from_curve` --- crates/fj-core/src/geometry/util/polyline.rs | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/fj-core/src/geometry/util/polyline.rs b/crates/fj-core/src/geometry/util/polyline.rs index 6282e5824..85f4cfd09 100644 --- a/crates/fj-core/src/geometry/util/polyline.rs +++ b/crates/fj-core/src/geometry/util/polyline.rs @@ -15,6 +15,31 @@ pub struct Polyline { pub points_curve: Vec>, } +impl Polyline { + /// # Create an instance of `Polyline` from a curve + pub fn from_curve( + curve: &dyn GenPolyline, + boundary: impl Into>>, + tolerance: impl Into, + ) -> Self { + let boundary = boundary.into(); + let tolerance = tolerance.into(); + + let points_curve = curve.generate_polyline(boundary, tolerance); + let points = points_curve + .iter() + .map(|&point_curve| { + convert_from_curve_point(curve, point_curve, tolerance) + }) + .collect(); + + Self { + points, + points_curve, + } + } +} + /// # Convert a point on a curve from curve coordinates to surface coordinates pub fn convert_from_curve_point( curve: &dyn GenPolyline,