Reduce garbage generation
This commit is contained in:
@@ -85,10 +85,11 @@ ol.geom.closest.getssMaxSquaredDelta =
|
|||||||
* @param {number} y Y.
|
* @param {number} y Y.
|
||||||
* @param {Array.<number>} closestPoint Closest point.
|
* @param {Array.<number>} closestPoint Closest point.
|
||||||
* @param {number} minSquaredDistance Minimum squared distance.
|
* @param {number} minSquaredDistance Minimum squared distance.
|
||||||
|
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
||||||
* @return {number} Minimum squared distance.
|
* @return {number} Minimum squared distance.
|
||||||
*/
|
*/
|
||||||
ol.geom.closest.getClosestPoint = function(flatCoordinates, offset, end, stride,
|
ol.geom.closest.getClosestPoint = function(flatCoordinates, offset, end, stride,
|
||||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance) {
|
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, opt_tmpPoint) {
|
||||||
if (offset == end) {
|
if (offset == end) {
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
}
|
}
|
||||||
@@ -106,17 +107,18 @@ ol.geom.closest.getClosestPoint = function(flatCoordinates, offset, end, stride,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
goog.asserts.assert(maxDelta > 0);
|
goog.asserts.assert(maxDelta > 0);
|
||||||
var point = [NaN, NaN];
|
var tmpPoint = goog.isDef(opt_tmpPoint) ? opt_tmpPoint : [NaN, NaN];
|
||||||
var index = offset + stride;
|
var index = offset + stride;
|
||||||
while (index < end) {
|
while (index < end) {
|
||||||
ol.geom.flat.closestPoint(x, y,
|
ol.geom.flat.closestPoint(x, y,
|
||||||
flatCoordinates[index - stride], flatCoordinates[index - stride + 1],
|
flatCoordinates[index - stride], flatCoordinates[index - stride + 1],
|
||||||
flatCoordinates[index], flatCoordinates[index + 1], point);
|
flatCoordinates[index], flatCoordinates[index + 1], tmpPoint);
|
||||||
squaredDistance = ol.geom.flat.squaredDistance(x, y, point[0], point[1]);
|
squaredDistance = ol.geom.flat.squaredDistance(
|
||||||
|
x, y, tmpPoint[0], tmpPoint[1]);
|
||||||
if (squaredDistance < minSquaredDistance) {
|
if (squaredDistance < minSquaredDistance) {
|
||||||
minSquaredDistance = squaredDistance;
|
minSquaredDistance = squaredDistance;
|
||||||
closestPoint[0] = point[0];
|
closestPoint[0] = tmpPoint[0];
|
||||||
closestPoint[1] = point[1];
|
closestPoint[1] = tmpPoint[1];
|
||||||
index += stride;
|
index += stride;
|
||||||
} else {
|
} else {
|
||||||
index += stride * Math.max(
|
index += stride * Math.max(
|
||||||
@@ -128,12 +130,13 @@ ol.geom.closest.getClosestPoint = function(flatCoordinates, offset, end, stride,
|
|||||||
// check the closing segment
|
// check the closing segment
|
||||||
ol.geom.flat.closestPoint(x, y,
|
ol.geom.flat.closestPoint(x, y,
|
||||||
flatCoordinates[end - stride], flatCoordinates[end - stride + 1],
|
flatCoordinates[end - stride], flatCoordinates[end - stride + 1],
|
||||||
flatCoordinates[offset], flatCoordinates[offset + 1], point);
|
flatCoordinates[offset], flatCoordinates[offset + 1], tmpPoint);
|
||||||
squaredDistance = ol.geom.flat.squaredDistance(x, y, point[0], point[1]);
|
squaredDistance = ol.geom.flat.squaredDistance(
|
||||||
|
x, y, tmpPoint[0], tmpPoint[1]);
|
||||||
if (squaredDistance < minSquaredDistance) {
|
if (squaredDistance < minSquaredDistance) {
|
||||||
minSquaredDistance = squaredDistance;
|
minSquaredDistance = squaredDistance;
|
||||||
closestPoint[0] = point[0];
|
closestPoint[0] = tmpPoint[0];
|
||||||
closestPoint[1] = point[1];
|
closestPoint[1] = tmpPoint[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
@@ -151,16 +154,19 @@ ol.geom.closest.getClosestPoint = function(flatCoordinates, offset, end, stride,
|
|||||||
* @param {number} y Y.
|
* @param {number} y Y.
|
||||||
* @param {Array.<number>} closestPoint Closest point.
|
* @param {Array.<number>} closestPoint Closest point.
|
||||||
* @param {number} minSquaredDistance Minimum squared distance.
|
* @param {number} minSquaredDistance Minimum squared distance.
|
||||||
|
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
||||||
* @return {number} Minimum squared distance.
|
* @return {number} Minimum squared distance.
|
||||||
*/
|
*/
|
||||||
ol.geom.closest.getsClosestPoint = function(flatCoordinates, offset, ends,
|
ol.geom.closest.getsClosestPoint = function(flatCoordinates, offset, ends,
|
||||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance) {
|
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||||
|
opt_tmpPoint) {
|
||||||
|
var tmpPoint = goog.isDef(opt_tmpPoint) ? opt_tmpPoint : [NaN, NaN];
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||||
var end = ends[i];
|
var end = ends[i];
|
||||||
minSquaredDistance = ol.geom.closest.getClosestPoint(
|
minSquaredDistance = ol.geom.closest.getClosestPoint(
|
||||||
flatCoordinates, offset, end, stride,
|
flatCoordinates, offset, end, stride,
|
||||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance);
|
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
@@ -178,16 +184,19 @@ ol.geom.closest.getsClosestPoint = function(flatCoordinates, offset, ends,
|
|||||||
* @param {number} y Y.
|
* @param {number} y Y.
|
||||||
* @param {Array.<number>} closestPoint Closest point.
|
* @param {Array.<number>} closestPoint Closest point.
|
||||||
* @param {number} minSquaredDistance Minimum squared distance.
|
* @param {number} minSquaredDistance Minimum squared distance.
|
||||||
|
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
||||||
* @return {number} Minimum squared distance.
|
* @return {number} Minimum squared distance.
|
||||||
*/
|
*/
|
||||||
ol.geom.closest.getssClosestPoint = function(flatCoordinates, offset, endss,
|
ol.geom.closest.getssClosestPoint = function(flatCoordinates, offset, endss,
|
||||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance) {
|
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||||
|
opt_tmpPoint) {
|
||||||
|
var tmpPoint = goog.isDef(opt_tmpPoint) ? opt_tmpPoint : [NaN, NaN];
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||||
var ends = endss[i];
|
var ends = endss[i];
|
||||||
minSquaredDistance = ol.geom.closest.getsClosestPoint(
|
minSquaredDistance = ol.geom.closest.getsClosestPoint(
|
||||||
flatCoordinates, offset, ends, stride,
|
flatCoordinates, offset, ends, stride,
|
||||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance);
|
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||||
offset = ends[ends.length - 1];
|
offset = ends[ends.length - 1];
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
|
|||||||
Reference in New Issue
Block a user