Skip to content

Commit

Permalink
Reverse segment order in CurveApprox::reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 6, 2023
1 parent c3ad019 commit 62968ab
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions crates/fj-core/src/algorithms/approx/curve/approx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,65 @@ 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();
}

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]),
],
},
],
}
)
}
}

0 comments on commit 62968ab

Please sign in to comment.