use std::cmp::Ordering;
use arithmetica::Sign;
use crate::exact::kernel::{on_segment, orient};
use crate::topology::areal::{AreaOperand, Areal, point_window, segment_window};
use crate::topology::de9im::IntersectionMatrix;
use crate::topology::label::{Dimension, Location};
use crate::types::{Coord2d, LineString, LinearRing, Polygon};
pub fn rings(poly: &Polygon) -> impl Iterator<Item = &LinearRing> {
std::iter::once(poly.exterior()).chain(poly.holes().iter())
}
pub fn locate(p: Coord2d, poly: &Polygon) -> Location {
Areal::single(poly).locate(p)
}
#[derive(Clone, Copy)]
struct Ray {
to: Coord2d,
is_out: bool,
}
fn incident_rays<A: AreaOperand + ?Sized>(x: Coord2d, area: &A) -> Vec<Ray> {
let mut out = Vec::new();
area.for_edges_near(&point_window(x), &mut |a, b| {
if a == x {
out.push(Ray {
to: b,
is_out: true,
});
} else if b == x {
out.push(Ray {
to: a,
is_out: false,
});
} else if on_segment(x, a, b) {
out.push(Ray {
to: b,
is_out: true,
});
out.push(Ray {
to: a,
is_out: false,
});
}
true
});
out
}
#[allow(clippy::float_cmp)]
fn upper_half(x: Coord2d, w: Coord2d) -> bool {
w.y > x.y || (w.y == x.y && w.x > x.x)
}
fn cmp_angle(x: Coord2d, u: Coord2d, v: Coord2d) -> Ordering {
match (upper_half(x, u), upper_half(x, v)) {
(true, false) => Ordering::Less,
(false, true) => Ordering::Greater,
_ => match orient(x, u, v) {
Sign::Positive => Ordering::Less,
Sign::Negative => Ordering::Greater,
Sign::Zero => Ordering::Equal,
},
}
}
#[cfg(test)]
fn location_ahead(x: Coord2d, toward: Coord2d, rays: &[Ray]) -> Location {
location_ahead_dir(x, toward, rays).0
}
fn location_ahead_dir(x: Coord2d, toward: Coord2d, rays: &[Ray]) -> (Location, Option<bool>) {
if let Some(r) = rays
.iter()
.find(|r| cmp_angle(x, r.to, toward) == Ordering::Equal)
{
return (Location::Boundary, Some(r.is_out));
}
let mut below: Option<&Ray> = None;
let mut greatest: Option<&Ray> = None;
for r in rays {
if cmp_angle(x, r.to, toward) == Ordering::Less
&& below.is_none_or(|b| cmp_angle(x, b.to, r.to) == Ordering::Less)
{
below = Some(r);
}
if greatest.is_none_or(|g| cmp_angle(x, g.to, r.to) == Ordering::Less) {
greatest = Some(r);
}
}
match below.or(greatest) {
Some(r) if r.is_out => (Location::Interior, None),
_ => (Location::Exterior, None),
}
}
#[allow(clippy::float_cmp)]
fn covered_by_segments(
a: Coord2d,
b: Coord2d,
segments: impl Iterator<Item = (Coord2d, Coord2d)>,
) -> bool {
let along = |c: Coord2d| if a.x == b.x { c.y } else { c.x };
let (lo, hi) = (along(a).min(along(b)), along(a).max(along(b)));
let mut intervals: Vec<(f64, f64)> = Vec::new();
for (c, d) in segments {
if orient(a, b, c) != Sign::Zero || orient(a, b, d) != Sign::Zero {
continue;
}
let ilo = along(c).min(along(d)).max(lo);
let ihi = along(c).max(along(d)).min(hi);
if ilo < ihi {
intervals.push((ilo, ihi));
}
}
intervals.sort_by(|x, y| x.0.total_cmp(&y.0));
let mut reach = lo;
for (ilo, ihi) in intervals {
if ilo > reach {
return false;
}
reach = reach.max(ihi);
if reach >= hi {
return true;
}
}
reach >= hi
}
fn mod2_boundary(parts: &[&LineString]) -> Vec<Coord2d> {
let mut ends: Vec<Coord2d> = parts.iter().flat_map(|l| [l.start(), l.end()]).collect();
ends.sort_by(|a, b| {
(a.x + 0.0)
.total_cmp(&(b.x + 0.0))
.then((a.y + 0.0).total_cmp(&(b.y + 0.0)))
});
let mut boundary = Vec::new();
let mut i = 0;
while i < ends.len() {
let mut j = i + 1;
while j < ends.len() && ends[j] == ends[i] {
j += 1;
}
if (j - i) % 2 == 1 {
boundary.push(ends[i]);
}
i = j;
}
boundary
}
pub(crate) struct LineSet<'a> {
parts: Vec<&'a LineString>,
boundary: Vec<Coord2d>,
}
impl<'a> LineSet<'a> {
pub(crate) fn single(line: &'a LineString) -> Self {
Self::new(vec![line])
}
pub(crate) fn new(parts: Vec<&'a LineString>) -> Self {
let boundary = mod2_boundary(&parts);
Self { parts, boundary }
}
pub(crate) fn boundary(&self) -> &[Coord2d] {
&self.boundary
}
pub(crate) fn segments(&self) -> impl Iterator<Item = (Coord2d, Coord2d)> + '_ {
self.parts
.iter()
.flat_map(|l| l.coords().as_slice().windows(2).map(|w| (w[0], w[1])))
}
pub(crate) fn bbox(&self) -> Option<crate::types::Bbox> {
crate::types::bbox_fold(self.parts.iter().map(|l| l.bbox()))
}
pub(crate) fn vertices(&self) -> impl Iterator<Item = Coord2d> + '_ {
self.parts
.iter()
.flat_map(|l| l.coords().as_slice().iter().copied())
}
pub(crate) fn contains(&self, x: Coord2d) -> bool {
self.segments().any(|(a, b)| on_segment(x, a, b))
}
pub(crate) fn locate(&self, x: Coord2d) -> Location {
if self.boundary.contains(&x) {
Location::Boundary
} else if self.contains(x) {
Location::Interior
} else {
Location::Exterior
}
}
}
#[allow(clippy::struct_excessive_bools)]
#[derive(Default)]
pub(crate) struct PieceSummary {
pub(crate) interior: bool,
pub(crate) boundary: bool,
pub(crate) exterior: bool,
pub(crate) shared_same: bool,
pub(crate) shared_opp: bool,
}
impl PieceSummary {
fn add_dir(&mut self, (loc, dir): (Location, Option<bool>)) {
self.add(loc);
match dir {
Some(true) => self.shared_same = true,
Some(false) => self.shared_opp = true,
None => {}
}
}
fn add(&mut self, loc: Location) {
match loc {
Location::Interior => self.interior = true,
Location::Boundary => self.boundary = true,
Location::Exterior => self.exterior = true,
}
}
}
pub(crate) fn summarize_segment<A: AreaOperand + ?Sized>(
p: Coord2d,
q: Coord2d,
area: &A,
out: &mut PieceSummary,
) {
for ev in segment_events(p, q, area) {
match ev.at {
EventAt::Point(x) => {
if area.locate(x) == Location::Boundary {
out.add_dir(location_ahead_dir(x, q, &incident_rays(x, area)));
} else {
out.add(ev.ahead);
}
}
EventAt::Crossing { .. } => out.add(ev.ahead),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum EventAt {
Point(Coord2d),
Crossing {
a: Coord2d,
b: Coord2d,
},
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SegmentEvent {
pub at: EventAt,
pub ahead: Location,
}
pub(crate) fn segment_events<A: AreaOperand + ?Sized>(
p: Coord2d,
q: Coord2d,
area: &A,
) -> Vec<SegmentEvent> {
let mut out = Vec::new();
let w = segment_window(p, q);
let ahead = match area.locate(p) {
Location::Boundary => location_ahead_dir(p, q, &incident_rays(p, area)).0,
loc => loc,
};
out.push(SegmentEvent {
at: EventAt::Point(p),
ahead,
});
let mut seen: Vec<Coord2d> = Vec::new();
area.for_vertices_near(&w, &mut |v| {
if v != p && v != q && on_segment(v, p, q) && !seen.contains(&v) {
seen.push(v);
let rays = incident_rays(v, area);
out.push(SegmentEvent {
at: EventAt::Point(v),
ahead: location_ahead_dir(v, q, &rays).0,
});
}
true
});
area.for_edges_near(&w, &mut |a, b| {
let (sa, sb) = (orient(p, q, a), orient(p, q, b));
let (sp, sq) = (orient(a, b, p), orient(a, b, q));
let opposite = |x: Sign, y: Sign| {
(x == Sign::Positive && y == Sign::Negative)
|| (x == Sign::Negative && y == Sign::Positive)
};
if !(opposite(sa, sb) && opposite(sp, sq)) {
return true;
}
if seen.iter().any(|&v| on_segment(v, a, b)) {
return true;
}
out.push(SegmentEvent {
at: EventAt::Crossing { a, b },
ahead: if sq == Sign::Positive {
Location::Interior
} else {
Location::Exterior
},
});
true
});
out
}
#[cfg(test)]
pub(crate) fn line_polygon_matrix(l: &LineString, poly: &Polygon) -> IntersectionMatrix {
lines_polygon_matrix(&LineSet::single(l), &Areal::single(poly))
}
fn mark(out: &mut [[bool; 3]; 2], row: usize, loc: Location) {
let k = match loc {
Location::Interior => 0,
Location::Boundary => 1,
Location::Exterior => 2,
};
out[row][k] = true;
}
pub(crate) fn lines_polygon_matrix<A: AreaOperand + ?Sized>(
lines: &LineSet<'_>,
area: &A,
) -> IntersectionMatrix {
let mut pieces = PieceSummary::default();
for (p, q) in lines.segments() {
summarize_segment(p, q, area, &mut pieces);
}
let bnd = lines.boundary();
let mut pts = [[false; 3]; 2];
for v in lines.vertices() {
let row = usize::from(bnd.contains(&v));
mark(&mut pts, row, area.locate(v));
}
for (p, q) in lines.segments() {
area.for_vertices_near(&segment_window(p, q), &mut |v| {
if !bnd.contains(&v) && v != p && v != q && on_segment(v, p, q) {
mark(&mut pts, 0, area.locate(v));
}
true
});
}
for (p, q) in lines.segments() {
let w = segment_window(p, q);
area.for_edges_near(&w, &mut |a, b| {
if !proper_crossing(p, q, a, b) {
return true;
}
let mut at_vertex = bnd
.iter()
.any(|&v| on_segment(v, p, q) && on_segment(v, a, b));
if !at_vertex {
area.for_vertices_near(&w, &mut |v| {
at_vertex = on_segment(v, p, q) && on_segment(v, a, b);
!at_vertex
});
}
if !at_vertex {
mark(&mut pts, 0, Location::Boundary);
}
!pts[0][1]
});
}
let lines_window = {
let mut w: Option<(Coord2d, Coord2d)> = None;
for v in lines.vertices() {
w = Some(match w {
None => (v, v),
Some((lo, hi)) => (
Coord2d::new(lo.x.min(v.x), lo.y.min(v.y)),
Coord2d::new(hi.x.max(v.x), hi.y.max(v.y)),
),
});
}
w.unwrap_or((Coord2d::new(0.0, 0.0), Coord2d::new(0.0, 0.0)))
};
let mut boundary_fully_covered = !area.has_edge_outside(&lines_window);
if boundary_fully_covered {
area.for_edges_near(&lines_window, &mut |a, b| {
boundary_fully_covered = covered_by_segments(a, b, lines.segments());
boundary_fully_covered
});
}
let cell = |line: bool, point: bool, d: Dimension| {
if line {
d
} else if point {
Dimension::Point
} else {
Dimension::Empty
}
};
let dim = |flag: bool, d: Dimension| if flag { d } else { Dimension::Empty };
IntersectionMatrix {
interior_interior: cell(pieces.interior, pts[0][0], Dimension::Line),
interior_boundary: cell(pieces.boundary, pts[0][1], Dimension::Line),
interior_exterior: cell(pieces.exterior, pts[0][2], Dimension::Line),
boundary_interior: dim(pts[1][0], Dimension::Point),
boundary_boundary: dim(pts[1][1], Dimension::Point),
boundary_exterior: dim(pts[1][2], Dimension::Point),
exterior_interior: Dimension::Area,
exterior_boundary: dim(!boundary_fully_covered, Dimension::Line),
exterior_exterior: Dimension::Area,
}
}
#[allow(clippy::float_cmp)]
pub(crate) fn collinear_overlap(a: Coord2d, b: Coord2d, c: Coord2d, d: Coord2d) -> bool {
if orient(a, b, c) != Sign::Zero || orient(a, b, d) != Sign::Zero {
return false;
}
let along = |p: Coord2d| if a.x == b.x { p.y } else { p.x };
let lo = along(a).min(along(b)).max(along(c).min(along(d)));
let hi = along(a).max(along(b)).min(along(c).max(along(d)));
lo < hi
}
pub(crate) fn proper_crossing(a: Coord2d, b: Coord2d, c: Coord2d, d: Coord2d) -> bool {
let opposite = |x: Sign, y: Sign| {
(x == Sign::Positive && y == Sign::Negative) || (x == Sign::Negative && y == Sign::Positive)
};
opposite(orient(a, b, c), orient(a, b, d)) && opposite(orient(c, d, a), orient(c, d, b))
}
#[cfg(test)]
pub(crate) fn line_line_matrix(a: &LineString, b: &LineString) -> IntersectionMatrix {
lines_lines_matrix(&LineSet::single(a), &LineSet::single(b))
}
pub(crate) fn lines_lines_matrix(a: &LineSet<'_>, b: &LineSet<'_>) -> IntersectionMatrix {
let (a_bnd, b_bnd) = (a.boundary(), b.boundary());
let any_bnd = |x: Coord2d| a_bnd.contains(&x) || b_bnd.contains(&x);
let mut overlap = false;
let mut ii_point = false;
for (a0, a1) in a.segments() {
for (b0, b1) in b.segments() {
if collinear_overlap(a0, a1, b0, b1) {
overlap = true;
} else if proper_crossing(a0, a1, b0, b1) {
let at_bnd = a_bnd
.iter()
.chain(b_bnd.iter())
.any(|&e| on_segment(e, a0, a1) && on_segment(e, b0, b1));
ii_point |= !at_bnd;
}
}
}
ii_point |= a.vertices().any(|v| !any_bnd(v) && b.contains(v));
ii_point |= b.vertices().any(|v| !any_bnd(v) && a.contains(v));
let ib = b_bnd.iter().any(|&e| !a_bnd.contains(&e) && a.contains(e));
let bi = a_bnd.iter().any(|&e| !b_bnd.contains(&e) && b.contains(e));
let bb = a_bnd.iter().any(|e| b_bnd.contains(e));
let be = a_bnd.iter().any(|&e| !b.contains(e));
let eb = b_bnd.iter().any(|&e| !a.contains(e));
let ie = a
.segments()
.any(|(p, q)| !covered_by_segments(p, q, b.segments()));
let ei = b
.segments()
.any(|(p, q)| !covered_by_segments(p, q, a.segments()));
let dim = |flag: bool, d: Dimension| if flag { d } else { Dimension::Empty };
IntersectionMatrix {
interior_interior: if overlap {
Dimension::Line
} else {
dim(ii_point, Dimension::Point)
},
interior_boundary: dim(ib, Dimension::Point),
interior_exterior: dim(ie, Dimension::Line),
boundary_interior: dim(bi, Dimension::Point),
boundary_boundary: dim(bb, Dimension::Point),
boundary_exterior: dim(be, Dimension::Point),
exterior_interior: dim(ei, Dimension::Line),
exterior_boundary: dim(eb, Dimension::Point),
exterior_exterior: Dimension::Area,
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
#[allow(
clippy::float_cmp,
clippy::cast_possible_truncation,
clippy::cast_precision_loss,
clippy::cast_possible_wrap,
clippy::range_plus_one,
clippy::no_effect_underscore_binding
)]
mod tests {
use super::*;
use crate::types::CoordSeq;
fn c(x: f64, y: f64) -> Coord2d {
Coord2d::new(x, y)
}
fn ring(pts: &[(f64, f64)]) -> LinearRing {
LinearRing::new(CoordSeq::new(pts.iter().map(|&(x, y)| c(x, y)).collect())).unwrap()
}
fn line(pts: &[(f64, f64)]) -> LineString {
LineString::new(CoordSeq::new(pts.iter().map(|&(x, y)| c(x, y)).collect())).unwrap()
}
fn square_with_hole() -> Polygon {
Polygon::new(
ring(&[(0.0, 0.0), (4.0, 0.0), (4.0, 4.0), (0.0, 4.0)]),
vec![ring(&[(1.0, 1.0), (1.0, 3.0), (3.0, 3.0), (3.0, 1.0)])],
)
.unwrap()
}
fn square() -> Polygon {
Polygon::new_simple(ring(&[(0.0, 0.0), (4.0, 0.0), (4.0, 4.0), (0.0, 4.0)])).unwrap()
}
#[test]
fn locate_classifies_all_regions() {
let p = square_with_hole();
assert_eq!(locate(c(0.5, 0.5), &p), Location::Interior);
assert_eq!(
locate(c(2.0, 2.0), &p),
Location::Exterior,
"inside the hole"
);
assert_eq!(locate(c(5.0, 5.0), &p), Location::Exterior);
assert_eq!(
locate(c(0.0, 0.0), &p),
Location::Boundary,
"exterior vertex"
);
assert_eq!(locate(c(2.0, 0.0), &p), Location::Boundary, "exterior edge");
assert_eq!(locate(c(1.0, 2.0), &p), Location::Boundary, "hole edge");
assert_eq!(locate(c(1.0, 1.0), &p), Location::Boundary, "hole vertex");
}
#[test]
fn locate_ray_through_vertex_is_counted_once() {
let chevron = Polygon::new_simple(ring(&[
(0.0, 0.0),
(4.0, 0.0),
(4.0, 4.0),
(0.0, 4.0),
(2.0, 2.0),
]))
.unwrap();
assert_eq!(
locate(c(1.0, 2.0), &chevron),
Location::Exterior,
"in the notch"
);
assert_eq!(locate(c(3.0, 2.0), &chevron), Location::Interior);
assert_eq!(locate(c(-1.0, 2.0), &chevron), Location::Exterior);
}
#[test]
fn cmp_angle_orders_counterclockwise_from_positive_x() {
let o = c(0.0, 0.0);
let dirs = [
c(1.0, 0.0),
c(1.0, 1.0),
c(0.0, 1.0),
c(-1.0, 0.0),
c(0.0, -1.0),
c(1.0, -1.0),
];
for w in dirs.windows(2) {
assert_eq!(cmp_angle(o, w[0], w[1]), Ordering::Less);
assert_eq!(cmp_angle(o, w[1], w[0]), Ordering::Greater);
}
assert_eq!(cmp_angle(o, c(1.0, 1.0), c(5.0, 5.0)), Ordering::Equal);
}
#[test]
fn location_ahead_at_convex_corner() {
let p = square();
let rays = incident_rays(c(0.0, 0.0), &Areal::single(&p));
assert_eq!(rays.len(), 2);
let at = |t: (f64, f64)| location_ahead(c(0.0, 0.0), c(t.0, t.1), &rays);
assert_eq!(at((1.0, 1.0)), Location::Interior);
assert_eq!(at((-1.0, 1.0)), Location::Exterior);
assert_eq!(at((-1.0, -1.0)), Location::Exterior);
assert_eq!(at((1.0, -1.0)), Location::Exterior);
assert_eq!(at((2.0, 0.0)), Location::Boundary, "along the out-edge");
assert_eq!(at((0.0, 2.0)), Location::Boundary, "along the in-edge");
}
#[test]
fn location_ahead_at_edge_interior_point() {
let p = square();
let rays = incident_rays(c(2.0, 0.0), &Areal::single(&p));
assert_eq!(
rays.len(),
2,
"an edge interior contributes both directions"
);
assert_eq!(
location_ahead(c(2.0, 0.0), c(2.0, 1.0), &rays),
Location::Interior
);
assert_eq!(
location_ahead(c(2.0, 0.0), c(2.0, -1.0), &rays),
Location::Exterior
);
assert_eq!(
location_ahead(c(2.0, 0.0), c(3.0, 0.0), &rays),
Location::Boundary
);
assert_eq!(
location_ahead(c(2.0, 0.0), c(1.0, 0.0), &rays),
Location::Boundary
);
}
#[test]
fn covered_by_segments_handles_gaps_and_joins() {
let cover = |a: Coord2d, b: Coord2d, pl: &[Coord2d]| {
covered_by_segments(a, b, pl.windows(2).map(|w| (w[0], w[1])))
};
let a = c(0.0, 0.0);
let b = c(4.0, 0.0);
let pl = |pts: &[(f64, f64)]| pts.iter().map(|&(x, y)| c(x, y)).collect::<Vec<_>>();
assert!(cover(a, b, &pl(&[(-1.0, 0.0), (2.0, 0.0), (5.0, 0.0)])));
assert!(cover(a, b, &pl(&[(0.0, 0.0), (2.0, 0.0), (4.0, 0.0)])));
assert!(!cover(
a,
b,
&pl(&[(0.0, 0.0), (1.0, 0.0), (1.0, 5.0), (3.0, 0.0), (4.0, 0.0)])
));
assert!(!cover(a, b, &pl(&[(0.0, 1.0), (4.0, 1.0)])));
assert!(cover(
c(0.0, 0.0),
c(0.0, 4.0),
&pl(&[(0.0, 5.0), (0.0, -1.0)])
));
}
#[test]
fn segment_crossing_the_boundary_reports_both_sides() {
let m = line_polygon_matrix(&line(&[(-1.0, 1.0), (5.0, 1.0)]), &square());
assert_eq!(m.to_string(), "101FF0212");
}
#[test]
fn line_through_hole_crosses_boundary_twice() {
let m = line_polygon_matrix(&line(&[(-1.0, 2.0), (5.0, 2.0)]), &square_with_hole());
assert_eq!(m.to_string(), "101FF0212");
}
#[test]
fn line_along_boundary_edge_is_boundary_overlap() {
let m = line_polygon_matrix(&line(&[(0.0, 0.0), (4.0, 0.0)]), &square());
assert_eq!(m.interior_boundary, Dimension::Line);
assert_eq!(m.boundary_boundary, Dimension::Point);
assert_eq!(m.interior_interior, Dimension::Empty);
assert_eq!(m.interior_exterior, Dimension::Empty);
assert_eq!(
m.exterior_boundary,
Dimension::Line,
"rest of the boundary is uncovered"
);
}
#[test]
fn closed_line_has_no_boundary_points() {
let tri = line(&[(1.0, 1.0), (3.0, 1.0), (2.0, 3.0), (1.0, 1.0)]);
let m = line_polygon_matrix(&tri, &square());
assert_eq!(m.boundary_interior, Dimension::Empty);
assert_eq!(m.boundary_boundary, Dimension::Empty);
assert_eq!(m.boundary_exterior, Dimension::Empty);
assert_eq!(m.interior_interior, Dimension::Line);
let other = line(&[(5.0, 5.0), (7.0, 5.0), (6.0, 7.0), (5.0, 5.0)]);
let mm = line_line_matrix(&tri, &other);
assert_eq!(mm.to_string(), "FF1FFF1F2");
}
#[test]
fn endpoint_touching_boundary_from_outside() {
let m = line_polygon_matrix(&line(&[(-2.0, 2.0), (0.0, 2.0)]), &square());
assert_eq!(m.boundary_boundary, Dimension::Point);
assert_eq!(m.boundary_exterior, Dimension::Point);
assert_eq!(
m.interior_boundary,
Dimension::Empty,
"touch is at an endpoint, not interior"
);
assert_eq!(m.interior_exterior, Dimension::Line);
}
#[test]
fn interior_vertex_touching_boundary_is_an_interior_point_contact() {
let m = line_polygon_matrix(&line(&[(6.0, 0.0), (4.0, 2.0), (6.0, 4.0)]), &square());
assert_eq!(m.interior_boundary, Dimension::Point);
assert_eq!(m.interior_interior, Dimension::Empty);
}
#[test]
fn line_line_t_junction_and_overlap() {
let a = line(&[(0.0, 0.0), (4.0, 0.0)]);
let b = line(&[(2.0, 0.0), (2.0, 3.0)]);
let m = line_line_matrix(&a, &b);
assert_eq!(m.to_string(), "F01FF0102");
let c2 = line(&[(1.0, 0.0), (6.0, 0.0)]);
let m2 = line_line_matrix(&a, &c2);
assert_eq!(m2.interior_interior, Dimension::Line);
assert_eq!(m2.interior_exterior, Dimension::Line);
assert_eq!(m2.exterior_interior, Dimension::Line);
}
#[test]
fn identical_lines_have_empty_exteriors() {
let a = line(&[(0.0, 0.0), (2.0, 2.0), (4.0, 0.0)]);
let m = line_line_matrix(&a, &a.clone());
assert_eq!(m.to_string(), "1FFF0FFF2");
}
#[test]
fn crossing_at_a_line_endpoint_is_not_an_interior_contact() {
let a = line(&[(2.0, 2.0), (0.0, 0.0), (4.0, 0.0), (2.0, 2.0), (3.0, 3.0)]);
let b = line(&[(2.0, 2.0), (2.0, 5.0)]);
let m = line_line_matrix(&a, &b);
assert_eq!(m.boundary_boundary, Dimension::Point);
}
}