Preserve extra dimensions in ol.geom.MultiPoint#closestPointXY
This commit is contained in:
@@ -42,14 +42,16 @@ ol.geom.MultiPoint.prototype.closestPointXY =
|
|||||||
}
|
}
|
||||||
var flatCoordinates = this.flatCoordinates;
|
var flatCoordinates = this.flatCoordinates;
|
||||||
var stride = this.stride;
|
var stride = this.stride;
|
||||||
var i, ii;
|
var i, ii, j;
|
||||||
for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||||
var squaredDistance = ol.geom.flat.squaredDistance(
|
var squaredDistance = ol.geom.flat.squaredDistance(
|
||||||
x, y, flatCoordinates[i], flatCoordinates[i + 1]);
|
x, y, flatCoordinates[i], flatCoordinates[i + 1]);
|
||||||
if (squaredDistance < minSquaredDistance) {
|
if (squaredDistance < minSquaredDistance) {
|
||||||
minSquaredDistance = squaredDistance;
|
minSquaredDistance = squaredDistance;
|
||||||
closestPoint[0] = flatCoordinates[i];
|
for (j = 0; j < stride; ++j) {
|
||||||
closestPoint[1] = flatCoordinates[i + 1];
|
closestPoint[j] = flatCoordinates[i + j];
|
||||||
|
}
|
||||||
|
closestPoint.length = stride;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
|
|||||||
@@ -154,6 +154,15 @@ describe('ol.geom.MultiPoint', function() {
|
|||||||
expect(multiPoint.getStride()).to.be(4);
|
expect(multiPoint.getStride()).to.be(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getClosestPoint', function() {
|
||||||
|
|
||||||
|
it('preserves extra dimensions', function() {
|
||||||
|
var closestPoint = multiPoint.getClosestPoint([6, 6]);
|
||||||
|
expect(closestPoint).to.eql([5, 6, 7, 8]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user