isInPolygon method
Implementation
bool isInPolygon(List<PointD> points) {
final int vertices = points.length;
// There must be at least 3 vertices in polygon
if (vertices < 3) {
return false;
}
final PointD extreme = PointD(double.maxFinite, y);
int count = 0;
for (int i = 0; i < vertices; i++) {
final PointD current = points[i];
final PointD next = points[(i + 1) % vertices];
if (Line(current, next).intersects(Line(this, extreme))) {
if (getOrientation(current, this, next) ==
PointsOrientation.collinear) {
return Line(current, next).onSegment(this);
}
count++;
}
}
// true if count is off
return count % 2 == 1;
}