Move overlaps test suite to boundary

This commit is contained in:
Hanno Braun 2023-09-29 10:15:14 +02:00
parent bcb00af1cb
commit b9aef596a1
2 changed files with 29 additions and 29 deletions

View File

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

View File

@ -130,3 +130,32 @@ impl CurveBoundaryElement for Point<1> {
impl CurveBoundaryElement for Vertex {
type Repr = HandleWrapper<Vertex>;
}
#[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<Point<1>> {
CurveBoundary::from(array.map(|element| [element]))
}
}
}