Make ol.geom.flat.lineStringInterpolate return flat coordinates

This commit is contained in:
Tom Payne
2014-01-23 02:02:39 +01:00
parent 23ade59d2f
commit 155d204938
+19 -13
View File
@@ -247,24 +247,25 @@ ol.geom.flat.inflateCoordinatesss =
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {number} fraction Fraction. * @param {number} fraction Fraction.
* @param {ol.Coordinate=} opt_point Point. * @param {Array.<number>=} opt_dest Destination.
* @return {ol.Coordinate} Point at fraction along the line string. * @return {Array.<number>} Destination.
*/ */
ol.geom.flat.lineStringInterpolate = ol.geom.flat.lineStringInterpolate =
function(flatCoordinates, offset, end, stride, fraction, opt_point) { function(flatCoordinates, offset, end, stride, fraction, opt_dest) {
// FIXME interpolate extra dimensions // FIXME interpolate extra dimensions
goog.asserts.assert(0 <= fraction && fraction <= 1); goog.asserts.assert(0 <= fraction && fraction <= 1);
var point = goog.isDef(opt_point) ? opt_point : [NaN, NaN]; var pointX = NaN;
var pointY = NaN;
var n = (end - offset) / stride; var n = (end - offset) / stride;
if (n === 0) { if (n === 0) {
goog.asserts.fail(); goog.asserts.fail();
} else if (n == 1) { } else if (n == 1) {
point[0] = flatCoordinates[offset]; pointX = flatCoordinates[offset];
point[1] = flatCoordinates[offset + 1]; pointY = flatCoordinates[offset + 1];
} else if (n == 2) { } else if (n == 2) {
point[0] = (1 - fraction) * flatCoordinates[offset] + pointX = (1 - fraction) * flatCoordinates[offset] +
fraction * flatCoordinates[offset + stride]; fraction * flatCoordinates[offset + stride];
point[1] = (1 - fraction) * flatCoordinates[offset + 1] + pointY = (1 - fraction) * flatCoordinates[offset + 1] +
fraction * flatCoordinates[offset + stride + 1]; fraction * flatCoordinates[offset + stride + 1];
} else { } else {
var x1 = flatCoordinates[offset]; var x1 = flatCoordinates[offset];
@@ -286,15 +287,20 @@ ol.geom.flat.lineStringInterpolate =
var t = (target - cumulativeLengths[-index - 2]) / var t = (target - cumulativeLengths[-index - 2]) /
(cumulativeLengths[-index - 1] - cumulativeLengths[-index - 2]); (cumulativeLengths[-index - 1] - cumulativeLengths[-index - 2]);
var o = offset + (-index - 2) * stride; var o = offset + (-index - 2) * stride;
point[0] = (1 - t) * flatCoordinates[o] + t * flatCoordinates[o + stride]; pointX = (1 - t) * flatCoordinates[o] + t * flatCoordinates[o + stride];
point[1] = (1 - t) * flatCoordinates[o + 1] + pointY = (1 - t) * flatCoordinates[o + 1] +
t * flatCoordinates[o + stride + 1]; t * flatCoordinates[o + stride + 1];
} else { } else {
point[0] = flatCoordinates[offset + index * stride]; pointX = flatCoordinates[offset + index * stride];
point[1] = flatCoordinates[offset + index * stride + 1]; pointY = flatCoordinates[offset + index * stride + 1];
} }
} }
return point; if (goog.isDefAndNotNull(opt_dest)) {
opt_dest.push(pointX, pointY);
return opt_dest;
} else {
return [pointX, pointY];
}
}; };