contains method
- Point point
Check if a point is inside this polygon
return false when:
- point is out side of the polygon
- point is on any sides or vertices
Implementation
bool contains(Point point) {
if (vertices.any((p) => p == point)) return true;
if (point.x < mostLeftPoint.x) return false;
if (point.y < bottomPoint.y) return false;
if (point.x > mostRightPoint.x) return false;
if (point.y > topPoint.y) return false;
if (edges.any((s) => s.hasPoint(point))) {
return true;
}
final ray = Line(point, Point(mostRightPoint.x + 2, point.y));
int intersects = 0;
for (var s in edges) {
if (ray.intersect(s)) {
intersects++;
}
}
return intersects % 2 != 0;
}