contains method

bool contains(
  1. LocationPoint p
)

Implementation

bool contains(LocationPoint p) {
  if (this.location == p.location &&
      this.subLocation == p.subLocation &&
      this.points.length >= 3) {
    int n = this.points.length;
    int count = 0;

    for (int i = 0; i < n; ++i) {
      LocationPoint p1 = this.points[i];
      LocationPoint p2 = this.points[(i + 1) % n];
      if (pointOnLine(p.x, p.y, p1.x, p1.y, p2.x, p2.y)) {
        return true;
      }

      if (xRayIntersectsLine(p.x, p.y, p1.x, p1.y, p2.x, p2.y)) {
        ++count;
      }
    }

    return count % 2 == 1;
  } else {
    return false;
  }
}