Add custom Ord impl for CurveApproxSegment

This commit is contained in:
Hanno Braun 2023-08-17 10:51:03 +02:00
parent e10b70fb99
commit 308c2aad65

View File

@ -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))
}
}