From be49a756d7f0bb5562c1d6395643f982815e5488 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 26 Aug 2022 14:14:15 +0200 Subject: [PATCH] Don't recompute point that is already available --- crates/fj-kernel/src/algorithms/approx/curve.rs | 13 +++++++------ crates/fj-kernel/src/algorithms/approx/edge.rs | 13 ++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index c83282718b..9ec6a211d7 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -64,9 +64,10 @@ fn approx_circle( let n = number_of_vertices_for_circle(tolerance, radius, range.length()); let mut points = Vec::new(); + points.push(range.start()); - for i in 0..n { - let angle = range.start().t + for i in 1..n { + let angle = range.start().0.t + (Scalar::TAU / n as f64 * i as f64) * range.direction(); let point_curve = Point::from([angle]); @@ -91,20 +92,20 @@ fn number_of_vertices_for_circle( } pub struct RangeOnCurve { - pub boundary: [Point<1>; 2], + pub boundary: [(Point<1>, Point<3>); 2], } impl RangeOnCurve { - fn start(&self) -> Point<1> { + fn start(&self) -> (Point<1>, Point<3>) { self.boundary[0] } - fn end(&self) -> Point<1> { + fn end(&self) -> (Point<1>, Point<3>) { self.boundary[1] } fn signed_length(&self) -> Scalar { - (self.end() - self.start()).t + (self.end().0 - self.start().0).t } fn length(&self) -> Scalar { diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index f8ff5556e7..1ac553167c 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -18,8 +18,19 @@ impl Approx for Edge { let start_curve = Point::from([Scalar::ZERO]); let end_curve = Point::from([Scalar::TAU]); + // We're dealing with a circle here. Start and end are identical + // points, in global coordinates. + let point_global = self + .global() + .curve() + .kind() + .point_from_curve_coords(start_curve); + RangeOnCurve { - boundary: [start_curve, end_curve], + boundary: [ + (start_curve, point_global), + (end_curve, point_global), + ], } };