diff --git a/geo/src/algorithm/contains/geometry.rs b/geo/src/algorithm/contains/geometry.rs index d5d957a92..50cce52c0 100644 --- a/geo/src/algorithm/contains/geometry.rs +++ b/geo/src/algorithm/contains/geometry.rs @@ -7,7 +7,7 @@ use crate::*; impl Contains> for Geometry where - T: GeoNum, + T: GeoFloat, { fn contains(&self, coord: &Coordinate) -> bool { match self { @@ -27,7 +27,7 @@ where impl Contains> for Geometry where - T: GeoNum, + T: GeoFloat, { fn contains(&self, point: &Point) -> bool { self.contains(&point.0) @@ -40,7 +40,7 @@ where impl Contains> for GeometryCollection where - T: GeoNum, + T: GeoFloat, { fn contains(&self, coord: &Coordinate) -> bool { self.iter().any(|geometry| geometry.contains(coord)) @@ -49,7 +49,7 @@ where impl Contains> for GeometryCollection where - T: GeoNum, + T: GeoFloat, { fn contains(&self, point: &Point) -> bool { self.contains(&point.0) diff --git a/geo/src/algorithm/contains/mod.rs b/geo/src/algorithm/contains/mod.rs index 68a72b7d1..52bfef168 100644 --- a/geo/src/algorithm/contains/mod.rs +++ b/geo/src/algorithm/contains/mod.rs @@ -370,16 +370,27 @@ mod test { #[test] fn line_in_polygon_test() { let c = |x, y| Coordinate { x, y }; - let line = Line::new(c(0, 10), c(30, 40)); - let linestring0 = line_string![c(-10, 0), c(50, 0), c(50, 50), c(0, 50), c(-10, 0)]; + let line = Line::new(c(0.0, 10.0), c(30.0, 40.0)); + let linestring0 = line_string![ + c(-10.0, 0.0), + c(50.0, 0.0), + c(50.0, 50.0), + c(0.0, 50.0), + c(-10.0, 0.0) + ]; let poly0 = Polygon::new(linestring0, Vec::new()); - let linestring1 = line_string![c(0, 0), c(0, 20), c(20, 20), c(20, 0), c(0, 0)]; + let linestring1 = line_string![ + c(0.0, 0.0), + c(0.0, 20.0), + c(20.0, 20.0), + c(20.0, 0.0), + c(0.0, 0.0) + ]; let poly1 = Polygon::new(linestring1, Vec::new()); assert!(poly0.contains(&line)); assert!(!poly1.contains(&line)); } #[test] - #[ignore] fn line_in_polygon_edgecases_test() { // Some DE-9IM edge cases for checking line is // inside polygon The end points of the line can be @@ -387,12 +398,18 @@ mod test { // that yet. let c = |x, y| Coordinate { x, y }; // A non-convex polygon - let linestring0 = line_string![c(0, 0), c(1, 1), c(1, -1), c(-1, -1), c(-1, 1)]; + let linestring0 = line_string![ + c(0.0, 0.0), + c(1.0, 1.0), + c(1.0, -1.0), + c(-1.0, -1.0), + c(-1.0, 1.0) + ]; let poly = Polygon::new(linestring0, Vec::new()); - assert!(poly.contains(&Line::new(c(0, 0), c(1, -1)))); - assert!(poly.contains(&Line::new(c(-1, 1), c(1, -1)))); - assert!(!poly.contains(&Line::new(c(-1, 1), c(1, 1)))); + assert!(poly.contains(&Line::new(c(0.0, 0.0), c(1.0, -1.0)))); + assert!(poly.contains(&Line::new(c(-1.0, 1.0), c(1.0, -1.0)))); + assert!(!poly.contains(&Line::new(c(-1.0, 1.0), c(1.0, 1.0)))); } #[test] fn line_in_linestring_edgecases() { diff --git a/geo/src/algorithm/contains/polygon.rs b/geo/src/algorithm/contains/polygon.rs index 6953438ba..af4be1bfc 100644 --- a/geo/src/algorithm/contains/polygon.rs +++ b/geo/src/algorithm/contains/polygon.rs @@ -1,14 +1,13 @@ use super::Contains; use crate::intersects::Intersects; -use crate::{CoordNum, Coordinate, GeoNum, Line, LineString, MultiPolygon, Point, Polygon}; +use crate::{CoordNum, Coordinate, GeoFloat, Line, LineString, MultiPolygon, Point, Polygon}; // ┌─────────────────────────────┐ // │ Implementations for Polygon │ // └─────────────────────────────┘ - impl Contains> for Polygon where - T: GeoNum, + T: GeoFloat, { fn contains(&self, coord: &Coordinate) -> bool { use crate::algorithm::coordinate_position::{CoordPos, CoordinatePosition}; @@ -19,7 +18,7 @@ where impl Contains> for Polygon where - T: GeoNum, + T: GeoFloat, { fn contains(&self, p: &Point) -> bool { self.contains(&p.0) @@ -30,7 +29,7 @@ where // line.start and line.end is on the boundaries impl Contains> for Polygon where - T: GeoNum, + T: GeoFloat, { fn contains(&self, line: &Line) -> bool { // both endpoints are contained in the polygon and the line @@ -45,7 +44,7 @@ where // TODO: also check interiors impl Contains> for Polygon where - T: GeoNum, + T: GeoFloat, { fn contains(&self, poly: &Polygon) -> bool { // decompose poly's exterior ring into Lines, and check each for containment @@ -56,7 +55,7 @@ where // TODO: ensure DE-9IM compliance impl Contains> for Polygon where - T: GeoNum, + T: GeoFloat, { fn contains(&self, linestring: &LineString) -> bool { // All LineString points must be inside the Polygon