Preserve extra dimensions in ol.geom.Point#closestPointXY
This commit is contained in:
@@ -40,8 +40,12 @@ ol.geom.Point.prototype.closestPointXY =
|
|||||||
var squaredDistance = ol.geom.flat.squaredDistance(
|
var squaredDistance = ol.geom.flat.squaredDistance(
|
||||||
x, y, flatCoordinates[0], flatCoordinates[1]);
|
x, y, flatCoordinates[0], flatCoordinates[1]);
|
||||||
if (squaredDistance < minSquaredDistance) {
|
if (squaredDistance < minSquaredDistance) {
|
||||||
closestPoint[0] = flatCoordinates[0];
|
var stride = this.stride;
|
||||||
closestPoint[1] = flatCoordinates[1];
|
var i;
|
||||||
|
for (i = 0; i < stride; ++i) {
|
||||||
|
closestPoint[i] = flatCoordinates[i];
|
||||||
|
}
|
||||||
|
closestPoint.length = stride;
|
||||||
return squaredDistance;
|
return squaredDistance;
|
||||||
} else {
|
} else {
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
|
|||||||
@@ -95,6 +95,15 @@ describe('ol.geom.Point', function() {
|
|||||||
expect(point.getStride()).to.be(4);
|
expect(point.getStride()).to.be(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getClosestPoint', function() {
|
||||||
|
|
||||||
|
it('preseves extra dimensions', function() {
|
||||||
|
var closestPoint = point.getClosestPoint([0, 0]);
|
||||||
|
expect(closestPoint).to.eql([1, 2, 3, 4]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user