From b9aef596a1c819356cbd196e22fb4e226f833b8d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 29 Sep 2023 10:15:14 +0200 Subject: [PATCH] Move `overlaps` test suite to `boundary` --- .../src/algorithms/approx/curve/segment.rs | 29 ------------------- crates/fj-core/src/geometry/boundary.rs | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/curve/segment.rs b/crates/fj-core/src/algorithms/approx/curve/segment.rs index 65255597e..5dc30242e 100644 --- a/crates/fj-core/src/algorithms/approx/curve/segment.rs +++ b/crates/fj-core/src/algorithms/approx/curve/segment.rs @@ -146,32 +146,3 @@ impl PartialOrd for CurveApproxSegment { Some(self.cmp(other)) } } - -#[cfg(test)] -mod tests { - use crate::algorithms::approx::curve::CurveApproxSegment; - - #[test] - fn overlaps() { - assert!(overlap([0., 2.], [1., 3.])); // regular overlap - assert!(overlap([0., 1.], [1., 2.])); // just touching - assert!(overlap([2., 0.], [3., 1.])); // not normalized - assert!(overlap([1., 3.], [0., 2.])); // lower boundary comes second - - assert!(!overlap([0., 1.], [2., 3.])); // regular non-overlap - assert!(!overlap([2., 3.], [0., 1.])); // lower boundary comes second - - fn overlap(a: [f64; 2], b: [f64; 2]) -> bool { - let a = CurveApproxSegment { - boundary: a.map(|coord| [coord]).into(), - points: Vec::new(), - }; - let b = CurveApproxSegment { - boundary: b.map(|coord| [coord]).into(), - points: Vec::new(), - }; - - a.overlaps(&b) - } - } -} diff --git a/crates/fj-core/src/geometry/boundary.rs b/crates/fj-core/src/geometry/boundary.rs index d9a23ec55..0f68432e0 100644 --- a/crates/fj-core/src/geometry/boundary.rs +++ b/crates/fj-core/src/geometry/boundary.rs @@ -130,3 +130,32 @@ impl CurveBoundaryElement for Point<1> { impl CurveBoundaryElement for Vertex { type Repr = HandleWrapper; } + +#[cfg(test)] +mod tests { + use fj_math::Point; + + use crate::geometry::CurveBoundary; + + #[test] + fn overlaps() { + assert!(overlap([0., 2.], [1., 3.])); // regular overlap + assert!(overlap([0., 1.], [1., 2.])); // just touching + assert!(overlap([2., 0.], [3., 1.])); // not normalized + assert!(overlap([1., 3.], [0., 2.])); // lower boundary comes second + + assert!(!overlap([0., 1.], [2., 3.])); // regular non-overlap + assert!(!overlap([2., 3.], [0., 1.])); // lower boundary comes second + + fn overlap(a: [f64; 2], b: [f64; 2]) -> bool { + let a = array_to_boundary(a); + let b = array_to_boundary(b); + + a.overlaps(&b) + } + + fn array_to_boundary(array: [f64; 2]) -> CurveBoundary> { + CurveBoundary::from(array.map(|element| [element])) + } + } +}