Polygon.Intersect.js 868 B

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