mirror of
https://github.com/hannobraun/Fornjot
synced 2025-09-08 18:36:58 +00:00
Add custom Ord
impl for CurveApproxSegment
This commit is contained in:
parent
e10b70fb99
commit
308c2aad65
@ -1,3 +1,5 @@
|
||||
use std::cmp;
|
||||
|
||||
use fj_math::Point;
|
||||
|
||||
use crate::{algorithms::approx::ApproxPoint, geometry::CurveBoundary};
|
||||
@ -8,7 +10,7 @@ use crate::{algorithms::approx::ApproxPoint, geometry::CurveBoundary};
|
||||
/// infinite, even if the curve itself isn't; a circle is an example of that).
|
||||
/// This means a curve can only be approximated locally, at a number of
|
||||
/// segments. This struct represents on such segment.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct CurveApproxSegment {
|
||||
/// The boundary within which this segment approximates the curve
|
||||
pub boundary: CurveBoundary<Point<1>>,
|
||||
@ -26,3 +28,23 @@ impl CurveApproxSegment {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for CurveApproxSegment {
|
||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||
let [a_start, a_end] = self.boundary.inner;
|
||||
let [b_start, b_end] = other.boundary.inner;
|
||||
|
||||
let by_start = a_start.cmp(&b_start);
|
||||
if by_start.is_ne() {
|
||||
return by_start;
|
||||
}
|
||||
|
||||
a_end.cmp(&b_end)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for CurveApproxSegment {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user