isPointInPolygon static method

bool isPointInPolygon(
  1. Point point,
  2. List<Point> vertices
)

Check if a Point point is inside a polygon representing by a List of Point vertices by using a Ray-Casting algorithm

Implementation

static bool isPointInPolygon(Point point, List<Point> vertices) {
  int intersectCount = 0;
  for (int i = 0; i < vertices.length; i += 1) {
    final Point vertB =
        i == vertices.length - 1 ? vertices[0] : vertices[i + 1];
    if (Poly.rayCastIntersect(point, vertices[i], vertB)) {
      intersectCount += 1;
    }
  }
  return (intersectCount % 2) == 1;
}