-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2009 from hannobraun/approx
Further prepare for more sophisticated curve approximation
- Loading branch information
Showing
5 changed files
with
158 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
//! Curve approximation | ||
mod approx; | ||
mod cache; | ||
mod segment; | ||
|
||
pub use self::{cache::CurveApproxCache, segment::CurveApproxSegment}; | ||
pub use self::{ | ||
approx::CurveApprox, cache::CurveApproxCache, segment::CurveApproxSegment, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use super::CurveApproxSegment; | ||
|
||
/// Partial approximation of a curve | ||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] | ||
pub struct CurveApprox { | ||
/// The approximated segments that are part of this approximation | ||
pub segments: Vec<CurveApproxSegment>, | ||
} | ||
|
||
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]), | ||
], | ||
}, | ||
], | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters