intersects method
Returns whether the two Polygons intersect.
Uses the toLineString
to check for intersections, rather than checking for shared volume.
Example:
Polygon poly1 = Polygon([
LinearRing([
Coordinate(0, 0),
Coordinate(0, 1),
Coordinate(1, 1),
Coordinate(1, 0),
Coordinate(0, 0),
]),
]);
Polygon poly2 = Polygon([
LinearRing([
Coordinate(0.5, 0.5),
Coordinate(0.5, 1.5),
Coordinate(1.5, 1.5),
Coordinate(1.5, 0.5),
Coordinate(0.5, 0.5),
]),
]);
print(poly1.intersects(poly2)); // true
Implementation
bool intersects(Polygon poly) {
return toLineString()
.intersections(poly.toLineString())
.features
.isNotEmpty;
}