From 62968aba3a8fc7671b687e48d6e0052c64355fca Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 6 Sep 2023 11:44:24 +0200 Subject: [PATCH] Reverse segment order in `CurveApprox::reverse` --- .../src/algorithms/approx/curve/approx.rs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/crates/fj-core/src/algorithms/approx/curve/approx.rs b/crates/fj-core/src/algorithms/approx/curve/approx.rs index f2ad1c484..63ab99b12 100644 --- a/crates/fj-core/src/algorithms/approx/curve/approx.rs +++ b/crates/fj-core/src/algorithms/approx/curve/approx.rs @@ -10,6 +10,8 @@ pub struct CurveApprox { impl CurveApprox { /// Reverse the approximation pub fn reverse(&mut self) -> &mut Self { + self.segments.reverse(); + for segment in &mut self.segments { segment.reverse(); } @@ -17,3 +19,56 @@ impl CurveApprox { self } } + +#[cfg(test)] +mod tests { + use crate::algorithms::approx::{curve::CurveApproxSegment, ApproxPoint}; + + use super::CurveApprox; + + #[test] + fn reverse() { + let mut approx = CurveApprox { + segments: vec![ + CurveApproxSegment { + boundary: [[0.1], [0.4]].into(), + points: vec![ + ApproxPoint::new([0.1], [0.1, 0.1, 0.1]), + ApproxPoint::new([0.4], [0.4, 0.4, 0.4]), + ], + }, + CurveApproxSegment { + boundary: [[0.6], [0.9]].into(), + points: vec![ + ApproxPoint::new([0.6], [0.6, 0.6, 0.6]), + ApproxPoint::new([0.9], [0.9, 0.9, 0.9]), + ], + }, + ], + }; + + approx.reverse(); + + assert_eq!( + approx, + CurveApprox { + segments: vec![ + CurveApproxSegment { + boundary: [[0.9], [0.6]].into(), + points: vec![ + ApproxPoint::new([0.9], [0.9, 0.9, 0.9]), + ApproxPoint::new([0.6], [0.6, 0.6, 0.6]), + ], + }, + CurveApproxSegment { + boundary: [[0.4], [0.1]].into(), + points: vec![ + ApproxPoint::new([0.4], [0.4, 0.4, 0.4]), + ApproxPoint::new([0.1], [0.1, 0.1, 0.1]), + ], + }, + ], + } + ) + } +}