diff --git a/README.md b/README.md index bfb6232f..61c4fd60 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ Controls: Known issues to be fixed: - - some IE7/8 glitches - show scaled background until tiles are loaded even with animation disabled ## Browser support diff --git a/src/geometry/LineUtil.js b/src/geometry/LineUtil.js index a7446767..0ab9342f 100644 --- a/src/geometry/LineUtil.js +++ b/src/geometry/LineUtil.js @@ -62,16 +62,10 @@ L.Util.extend(L.LineUtil, { }, _sqPointToSegmentDist: function(p, p1, p2) { - var l2 = this._sqDist(p1, p2); - - if (l2 == 0) return this._sqDist(p, p1); - - var x1 = p.x - p1.x, - x2 = p2.x - p1.x, - y1 = p.y - p1.y, + var x2 = p2.x - p1.x, y2 = p2.y - p1.y, - dot = x1 * x2 + y1 * y2, - t = dot / l2; + dot = (p.x - p1.x) * x2 + (p.y - p1.y) * y2, + t = dot / this._sqDist(p1, p2); if (t < 0) return this._sqDist(p, p1); if (t > 1) return this._sqDist(p, p2); @@ -84,13 +78,16 @@ L.Util.extend(L.LineUtil, { L.Util.extend(L.LineUtil, { // Cohen-Sutherland line segment clipping algorithm // it's considered the fastest in case most clippings are trivial accepts or rejects - clipSegment: function(a, b, bounds) { + clipSegment: function(a, b, bounds, useLastCode) { var min = bounds.min, max = bounds.max; - var codeA = this._getBitCode(a, bounds), + var codeA = useLastCode ? this._lastCode : this._getBitCode(a, bounds), codeB = this._getBitCode(b, bounds); + // save 2nd code to avoid calculating it on the next segment + this._lastCode = codeB; + while (true) { if (!(codeA | codeB)) { return [a, b]; diff --git a/src/geometry/Point.js b/src/geometry/Point.js index f972cb13..1b988391 100644 --- a/src/geometry/Point.js +++ b/src/geometry/Point.js @@ -13,7 +13,14 @@ L.Point.prototype = { }, subtract: function(point) { - return new L.Point(this.x - point.x, this.y - point.y); + return this.clone()._subtract(point); + }, + + // destructive subtract (faster) + _subtract: function(point) { + this.x -= point.x; + this.y -= point.y; + return this; }, divideBy: function(num, round) { diff --git a/src/geometry/Transformation.js b/src/geometry/Transformation.js index 439d4481..37f40968 100644 --- a/src/geometry/Transformation.js +++ b/src/geometry/Transformation.js @@ -10,11 +10,16 @@ L.Transformation = L.Class.extend({ this._d = d; }, - transform: function(/*Point*/ point, /*Number*/ scale) /*-> Point*/ { + transform: function(point, scale) { + return this._transform(point.clone(), scale); + }, + + // destructive transform (faster) + _transform: function(/*Point*/ point, /*Number*/ scale) /*-> Point*/ { scale = scale || 1; - return new L.Point( - scale * (this._a * point.x + this._b), - scale * (this._c * point.y + this._d)); + point.x = scale * (this._a * point.x + this._b); + point.y = scale * (this._c * point.y + this._d); + return point; }, untransform: function(/*Point*/ point, /*Number*/ scale) /*-> Point*/ { diff --git a/src/layer/vector/Polyline.js b/src/layer/vector/Polyline.js index 59470872..706282be 100644 --- a/src/layer/vector/Polyline.js +++ b/src/layer/vector/Polyline.js @@ -58,7 +58,7 @@ L.Polyline = L.Path.extend({ this._parts = []; for (i = 0, k = 0; i < len - 1; i++) { - segment = L.LineUtil.clipSegment(points[i], points[i+1], this._map._pathViewport); + segment = L.LineUtil.clipSegment(points[i], points[i+1], this._map._pathViewport, i); if (!segment) continue; this._parts[k] = this._parts[k] || []; diff --git a/src/map/Map.js b/src/map/Map.js index 53449c33..a8941004 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -230,13 +230,13 @@ L.Map = L.Class.extend({ }, latLngToLayerPoint: function(latlng) { - return this.project(latlng).subtract(this._initialTopLeftPoint); + return this.project(latlng)._subtract(this._initialTopLeftPoint); }, project: function(/*Object*/ coord, /*(optional) Number*/ zoom)/*-> Point*/ { var projectedPoint = this.options.projection.project(coord), scale = this.options.scaling(isNaN(zoom) ? this._zoom : zoom); - return this.options.transformation.transform(projectedPoint, scale); + return this.options.transformation._transform(projectedPoint, scale); }, unproject: function(/*Point*/ point, /*(optional) Number*/ zoom, /*(optional) Boolean*/ unbounded)/*-> Object*/ {