diff --git a/crates/fj-core/src/algorithms/approx/curve/segment.rs b/crates/fj-core/src/algorithms/approx/curve/segment.rs index d56ebb680..d0d8fcb05 100644 --- a/crates/fj-core/src/algorithms/approx/curve/segment.rs +++ b/crates/fj-core/src/algorithms/approx/curve/segment.rs @@ -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>, @@ -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 { + Some(self.cmp(other)) + } +}