Polygon.Intersect.js 782 B

123456789101112131415161718192021222324252627
  1. L.Polygon.include({
  2. // Checks a polygon for any intersecting line segments. Ignores holes.
  3. intersects: function () {
  4. var polylineIntersects,
  5. points = this._originalPoints,
  6. len, firstPoint, lastPoint, maxIndex;
  7. if (this._tooFewPointsForIntersection()) {
  8. return false;
  9. }
  10. polylineIntersects = L.Polyline.prototype.intersects.call(this);
  11. // If already found an intersection don't need to check for any more.
  12. if (polylineIntersects) {
  13. return true;
  14. }
  15. len = points.length;
  16. firstPoint = points[0];
  17. lastPoint = points[len - 1];
  18. maxIndex = len - 2;
  19. // Check the line segment between last and first point. Don't need to check the first line segment (minIndex = 1)
  20. return this._lineSegmentsIntersectsRange(lastPoint, firstPoint, maxIndex, 1);
  21. }
  22. });