1L.Polyline.include({ 2 // Check to see if this polyline has any linesegments that intersect. 3 // NOTE: does not support detecting intersection for degenerate cases. 4 intersects: function () { 5 var points = this._originalPoints, 6 len = points ? points.length : 0, 7 i, p, p1; 8 9 if (this._tooFewPointsForIntersection()) { 10 return false; 11 } 12 13 for (i = len - 1; i >= 3; i--) { 14 p = points[i - 1]; 15 p1 = points[i]; 16 17 18 if (this._lineSegmentsIntersectsRange(p, p1, i - 2)) { 19 return true; 20 } 21 } 22 23 return false; 24 }, 25 26 // Check for intersection if new latlng was added to this polyline. 27 // NOTE: does not support detecting intersection for degenerate cases. 28 newLatLngIntersects: function (latlng, skipFirst) { 29 // Cannot check a polyline for intersecting lats/lngs when not added to the map 30 if (!this._map) { 31 return false; 32 } 33 34 return this.newPointIntersects(this._map.latLngToLayerPoint(latlng), skipFirst); 35 }, 36 37 // Check for intersection if new point was added to this polyline. 38 // newPoint must be a layer point. 39 // NOTE: does not support detecting intersection for degenerate cases. 40 newPointIntersects: function (newPoint, skipFirst) { 41 var points = this._originalPoints, 42 len = points ? points.length : 0, 43 lastPoint = points ? points[len - 1] : null, 44 // The previous previous line segment. Previous line segment doesn't need testing. 45 maxIndex = len - 2; 46 47 if (this._tooFewPointsForIntersection(1)) { 48 return false; 49 } 50 51 return this._lineSegmentsIntersectsRange(lastPoint, newPoint, maxIndex, skipFirst ? 1 : 0); 52 }, 53 54 // Polylines with 2 sides can only intersect in cases where points are collinear (we don't support detecting these). 55 // Cannot have intersection when < 3 line segments (< 4 points) 56 _tooFewPointsForIntersection: function (extraPoints) { 57 var points = this._originalPoints, 58 len = points ? points.length : 0; 59 // Increment length by extraPoints if present 60 len += extraPoints || 0; 61 62 return !this._originalPoints || len <= 3; 63 }, 64 65 // Checks a line segment intersections with any line segments before its predecessor. 66 // Don't need to check the predecessor as will never intersect. 67 _lineSegmentsIntersectsRange: function (p, p1, maxIndex, minIndex) { 68 var points = this._originalPoints, 69 p2, p3; 70 71 minIndex = minIndex || 0; 72 73 // Check all previous line segments (beside the immediately previous) for intersections 74 for (var j = maxIndex; j > minIndex; j--) { 75 p2 = points[j - 1]; 76 p3 = points[j]; 77 78 if (L.LineUtil.segmentsIntersect(p, p1, p2, p3)) { 79 return true; 80 } 81 } 82 83 return false; 84 } 85});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.