Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
+12
-12
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/area
|
||||
*/
|
||||
var _ol_geom_flat_area_ = {};
|
||||
const _ol_geom_flat_area_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,12 +12,12 @@ var _ol_geom_flat_area_ = {};
|
||||
* @return {number} Area.
|
||||
*/
|
||||
_ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride) {
|
||||
var twiceArea = 0;
|
||||
var x1 = flatCoordinates[end - stride];
|
||||
var y1 = flatCoordinates[end - stride + 1];
|
||||
let twiceArea = 0;
|
||||
let x1 = flatCoordinates[end - stride];
|
||||
let y1 = flatCoordinates[end - stride + 1];
|
||||
for (; offset < end; offset += stride) {
|
||||
var x2 = flatCoordinates[offset];
|
||||
var y2 = flatCoordinates[offset + 1];
|
||||
const x2 = flatCoordinates[offset];
|
||||
const y2 = flatCoordinates[offset + 1];
|
||||
twiceArea += y1 * x2 - x1 * y2;
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
@@ -34,10 +34,10 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride)
|
||||
* @return {number} Area.
|
||||
*/
|
||||
_ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride) {
|
||||
var area = 0;
|
||||
var i, ii;
|
||||
let area = 0;
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const end = ends[i];
|
||||
area += _ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride);
|
||||
offset = end;
|
||||
}
|
||||
@@ -53,10 +53,10 @@ _ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride
|
||||
* @return {number} Area.
|
||||
*/
|
||||
_ol_geom_flat_area_.linearRingss = function(flatCoordinates, offset, endss, stride) {
|
||||
var area = 0;
|
||||
var i, ii;
|
||||
let area = 0;
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
area +=
|
||||
_ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride);
|
||||
offset = ends[ends.length - 1];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @module ol/geom/flat/center
|
||||
*/
|
||||
import {createEmpty, createOrUpdateFromFlatCoordinates} from '../../extent.js';
|
||||
var _ol_geom_flat_center_ = {};
|
||||
const _ol_geom_flat_center_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,11 +13,11 @@ var _ol_geom_flat_center_ = {};
|
||||
* @return {Array.<number>} Flat centers.
|
||||
*/
|
||||
_ol_geom_flat_center_.linearRingss = function(flatCoordinates, offset, endss, stride) {
|
||||
var flatCenters = [];
|
||||
var i, ii;
|
||||
var extent = createEmpty();
|
||||
const flatCenters = [];
|
||||
let i, ii;
|
||||
let extent = createEmpty();
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
extent = createOrUpdateFromFlatCoordinates(flatCoordinates, offset, ends[0], stride);
|
||||
flatCenters.push((extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2);
|
||||
offset = ends[ends.length - 1];
|
||||
|
||||
+42
-42
@@ -2,7 +2,7 @@
|
||||
* @module ol/geom/flat/closest
|
||||
*/
|
||||
import {lerp, squaredDistance as squaredDx} from '../../math.js';
|
||||
var _ol_geom_flat_closest_ = {};
|
||||
const _ol_geom_flat_closest_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,21 +18,21 @@ var _ol_geom_flat_closest_ = {};
|
||||
* @param {Array.<number>} closestPoint Closest point.
|
||||
*/
|
||||
_ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) {
|
||||
var x1 = flatCoordinates[offset1];
|
||||
var y1 = flatCoordinates[offset1 + 1];
|
||||
var dx = flatCoordinates[offset2] - x1;
|
||||
var dy = flatCoordinates[offset2 + 1] - y1;
|
||||
var i, offset;
|
||||
const x1 = flatCoordinates[offset1];
|
||||
const y1 = flatCoordinates[offset1 + 1];
|
||||
const dx = flatCoordinates[offset2] - x1;
|
||||
const dy = flatCoordinates[offset2 + 1] - y1;
|
||||
let i, offset;
|
||||
if (dx === 0 && dy === 0) {
|
||||
offset = offset1;
|
||||
} else {
|
||||
var t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
|
||||
const t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
|
||||
if (t > 1) {
|
||||
offset = offset2;
|
||||
} else if (t > 0) {
|
||||
for (i = 0; i < stride; ++i) {
|
||||
closestPoint[i] = lerp(flatCoordinates[offset1 + i],
|
||||
flatCoordinates[offset2 + i], t);
|
||||
flatCoordinates[offset2 + i], t);
|
||||
}
|
||||
closestPoint.length = stride;
|
||||
return;
|
||||
@@ -58,12 +58,12 @@ _ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, strid
|
||||
* @return {number} Max squared delta.
|
||||
*/
|
||||
_ol_geom_flat_closest_.getMaxSquaredDelta = function(flatCoordinates, offset, end, stride, maxSquaredDelta) {
|
||||
var x1 = flatCoordinates[offset];
|
||||
var y1 = flatCoordinates[offset + 1];
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
for (offset += stride; offset < end; offset += stride) {
|
||||
var x2 = flatCoordinates[offset];
|
||||
var y2 = flatCoordinates[offset + 1];
|
||||
var squaredDelta = squaredDx(x1, y1, x2, y2);
|
||||
const x2 = flatCoordinates[offset];
|
||||
const y2 = flatCoordinates[offset + 1];
|
||||
const squaredDelta = squaredDx(x1, y1, x2, y2);
|
||||
if (squaredDelta > maxSquaredDelta) {
|
||||
maxSquaredDelta = squaredDelta;
|
||||
}
|
||||
@@ -83,11 +83,11 @@ _ol_geom_flat_closest_.getMaxSquaredDelta = function(flatCoordinates, offset, en
|
||||
* @return {number} Max squared delta.
|
||||
*/
|
||||
_ol_geom_flat_closest_.getsMaxSquaredDelta = function(flatCoordinates, offset, ends, stride, maxSquaredDelta) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const end = ends[i];
|
||||
maxSquaredDelta = _ol_geom_flat_closest_.getMaxSquaredDelta(
|
||||
flatCoordinates, offset, end, stride, maxSquaredDelta);
|
||||
flatCoordinates, offset, end, stride, maxSquaredDelta);
|
||||
offset = end;
|
||||
}
|
||||
return maxSquaredDelta;
|
||||
@@ -103,11 +103,11 @@ _ol_geom_flat_closest_.getsMaxSquaredDelta = function(flatCoordinates, offset, e
|
||||
* @return {number} Max squared delta.
|
||||
*/
|
||||
_ol_geom_flat_closest_.getssMaxSquaredDelta = function(flatCoordinates, offset, endss, stride, maxSquaredDelta) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
maxSquaredDelta = _ol_geom_flat_closest_.getsMaxSquaredDelta(
|
||||
flatCoordinates, offset, ends, stride, maxSquaredDelta);
|
||||
flatCoordinates, offset, ends, stride, maxSquaredDelta);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return maxSquaredDelta;
|
||||
@@ -129,16 +129,16 @@ _ol_geom_flat_closest_.getssMaxSquaredDelta = function(flatCoordinates, offset,
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
_ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
if (offset == end) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
var i, squaredDistance;
|
||||
let i, squaredDistance;
|
||||
if (maxDelta === 0) {
|
||||
// All points are identical, so just test the first point.
|
||||
squaredDistance = squaredDx(
|
||||
x, y, flatCoordinates[offset], flatCoordinates[offset + 1]);
|
||||
x, y, flatCoordinates[offset], flatCoordinates[offset + 1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
for (i = 0; i < stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[offset + i];
|
||||
@@ -149,11 +149,11 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
return minSquaredDistance;
|
||||
}
|
||||
}
|
||||
var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
var index = offset + stride;
|
||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
let index = offset + stride;
|
||||
while (index < end) {
|
||||
_ol_geom_flat_closest_.point(
|
||||
flatCoordinates, index - stride, index, stride, x, y, tmpPoint);
|
||||
flatCoordinates, index - stride, index, stride, x, y, tmpPoint);
|
||||
squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
@@ -174,14 +174,14 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
// finding a closer point. We use Math.max(..., 1) to ensure that we
|
||||
// always advance at least one point, to avoid an infinite loop.
|
||||
index += stride * Math.max(
|
||||
((Math.sqrt(squaredDistance) -
|
||||
((Math.sqrt(squaredDistance) -
|
||||
Math.sqrt(minSquaredDistance)) / maxDelta) | 0, 1);
|
||||
}
|
||||
}
|
||||
if (isRing) {
|
||||
// Check the closing segment.
|
||||
_ol_geom_flat_closest_.point(
|
||||
flatCoordinates, end - stride, offset, stride, x, y, tmpPoint);
|
||||
flatCoordinates, end - stride, offset, stride, x, y, tmpPoint);
|
||||
squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
@@ -210,15 +210,15 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
_ol_geom_flat_closest_.getsClosestPoint = function(flatCoordinates, offset, ends,
|
||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
var i, ii;
|
||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const end = ends[i];
|
||||
minSquaredDistance = _ol_geom_flat_closest_.getClosestPoint(
|
||||
flatCoordinates, offset, end, stride,
|
||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||
flatCoordinates, offset, end, stride,
|
||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||
offset = end;
|
||||
}
|
||||
return minSquaredDistance;
|
||||
@@ -240,15 +240,15 @@ _ol_geom_flat_closest_.getsClosestPoint = function(flatCoordinates, offset, ends
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
_ol_geom_flat_closest_.getssClosestPoint = function(flatCoordinates, offset,
|
||||
endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
var i, ii;
|
||||
endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
minSquaredDistance = _ol_geom_flat_closest_.getsClosestPoint(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||
flatCoordinates, offset, ends, stride,
|
||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return minSquaredDistance;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @module ol/geom/flat/contains
|
||||
*/
|
||||
import {forEachCorner} from '../../extent.js';
|
||||
var _ol_geom_flat_contains_ = {};
|
||||
const _ol_geom_flat_contains_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,15 +14,15 @@ var _ol_geom_flat_contains_ = {};
|
||||
* @return {boolean} Contains extent.
|
||||
*/
|
||||
_ol_geom_flat_contains_.linearRingContainsExtent = function(flatCoordinates, offset, end, stride, extent) {
|
||||
var outside = forEachCorner(extent,
|
||||
/**
|
||||
const outside = forEachCorner(extent,
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
function(coordinate) {
|
||||
return !_ol_geom_flat_contains_.linearRingContainsXY(flatCoordinates,
|
||||
offset, end, stride, coordinate[0], coordinate[1]);
|
||||
});
|
||||
function(coordinate) {
|
||||
return !_ol_geom_flat_contains_.linearRingContainsXY(flatCoordinates,
|
||||
offset, end, stride, coordinate[0], coordinate[1]);
|
||||
});
|
||||
return !outside;
|
||||
};
|
||||
|
||||
@@ -44,12 +44,12 @@ _ol_geom_flat_contains_.linearRingContainsXY = function(flatCoordinates, offset,
|
||||
// SoftSurfer makes no warranty for this code, and cannot be held
|
||||
// liable for any real or imagined damage resulting from its use.
|
||||
// Users of this code must verify correctness for their application.
|
||||
var wn = 0;
|
||||
var x1 = flatCoordinates[end - stride];
|
||||
var y1 = flatCoordinates[end - stride + 1];
|
||||
let wn = 0;
|
||||
let x1 = flatCoordinates[end - stride];
|
||||
let y1 = flatCoordinates[end - stride + 1];
|
||||
for (; offset < end; offset += stride) {
|
||||
var x2 = flatCoordinates[offset];
|
||||
var y2 = flatCoordinates[offset + 1];
|
||||
const x2 = flatCoordinates[offset];
|
||||
const y2 = flatCoordinates[offset + 1];
|
||||
if (y1 <= y) {
|
||||
if (y2 > y && ((x2 - x1) * (y - y1)) - ((x - x1) * (y2 - y1)) > 0) {
|
||||
wn++;
|
||||
@@ -78,13 +78,13 @@ _ol_geom_flat_contains_.linearRingsContainsXY = function(flatCoordinates, offset
|
||||
return false;
|
||||
}
|
||||
if (!_ol_geom_flat_contains_.linearRingContainsXY(
|
||||
flatCoordinates, offset, ends[0], stride, x, y)) {
|
||||
flatCoordinates, offset, ends[0], stride, x, y)) {
|
||||
return false;
|
||||
}
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 1, ii = ends.length; i < ii; ++i) {
|
||||
if (_ol_geom_flat_contains_.linearRingContainsXY(
|
||||
flatCoordinates, ends[i - 1], ends[i], stride, x, y)) {
|
||||
flatCoordinates, ends[i - 1], ends[i], stride, x, y)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -105,11 +105,11 @@ _ol_geom_flat_contains_.linearRingssContainsXY = function(flatCoordinates, offse
|
||||
if (endss.length === 0) {
|
||||
return false;
|
||||
}
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
if (_ol_geom_flat_contains_.linearRingsContainsXY(
|
||||
flatCoordinates, offset, ends, stride, x, y)) {
|
||||
flatCoordinates, offset, ends, stride, x, y)) {
|
||||
return true;
|
||||
}
|
||||
offset = ends[ends.length - 1];
|
||||
|
||||
+15
-16
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/deflate
|
||||
*/
|
||||
var _ol_geom_flat_deflate_ = {};
|
||||
const _ol_geom_flat_deflate_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ var _ol_geom_flat_deflate_ = {};
|
||||
* @return {number} offset Offset.
|
||||
*/
|
||||
_ol_geom_flat_deflate_.coordinate = function(flatCoordinates, offset, coordinate, stride) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = coordinate.length; i < ii; ++i) {
|
||||
flatCoordinates[offset++] = coordinate[i];
|
||||
}
|
||||
@@ -28,11 +28,10 @@ _ol_geom_flat_deflate_.coordinate = function(flatCoordinates, offset, coordinate
|
||||
* @return {number} offset Offset.
|
||||
*/
|
||||
_ol_geom_flat_deflate_.coordinates = function(flatCoordinates, offset, coordinates, stride) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
var coordinate = coordinates[i];
|
||||
var j;
|
||||
for (j = 0; j < stride; ++j) {
|
||||
const coordinate = coordinates[i];
|
||||
for (let j = 0; j < stride; ++j) {
|
||||
flatCoordinates[offset++] = coordinate[j];
|
||||
}
|
||||
}
|
||||
@@ -49,12 +48,12 @@ _ol_geom_flat_deflate_.coordinates = function(flatCoordinates, offset, coordinat
|
||||
* @return {Array.<number>} Ends.
|
||||
*/
|
||||
_ol_geom_flat_deflate_.coordinatess = function(flatCoordinates, offset, coordinatess, stride, opt_ends) {
|
||||
var ends = opt_ends ? opt_ends : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
const ends = opt_ends ? opt_ends : [];
|
||||
let i = 0;
|
||||
let j, jj;
|
||||
for (j = 0, jj = coordinatess.length; j < jj; ++j) {
|
||||
var end = _ol_geom_flat_deflate_.coordinates(
|
||||
flatCoordinates, offset, coordinatess[j], stride);
|
||||
const end = _ol_geom_flat_deflate_.coordinates(
|
||||
flatCoordinates, offset, coordinatess[j], stride);
|
||||
ends[i++] = end;
|
||||
offset = end;
|
||||
}
|
||||
@@ -72,12 +71,12 @@ _ol_geom_flat_deflate_.coordinatess = function(flatCoordinates, offset, coordina
|
||||
* @return {Array.<Array.<number>>} Endss.
|
||||
*/
|
||||
_ol_geom_flat_deflate_.coordinatesss = function(flatCoordinates, offset, coordinatesss, stride, opt_endss) {
|
||||
var endss = opt_endss ? opt_endss : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
const endss = opt_endss ? opt_endss : [];
|
||||
let i = 0;
|
||||
let j, jj;
|
||||
for (j = 0, jj = coordinatesss.length; j < jj; ++j) {
|
||||
var ends = _ol_geom_flat_deflate_.coordinatess(
|
||||
flatCoordinates, offset, coordinatesss[j], stride, endss[i]);
|
||||
const ends = _ol_geom_flat_deflate_.coordinatess(
|
||||
flatCoordinates, offset, coordinatesss[j], stride, endss[i]);
|
||||
endss[i++] = ends;
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/flip
|
||||
*/
|
||||
var _ol_geom_flat_flip_ = {};
|
||||
const _ol_geom_flat_flip_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ var _ol_geom_flat_flip_ = {};
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
_ol_geom_flat_flip_.flipXY = function(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) {
|
||||
var dest, destOffset;
|
||||
let dest, destOffset;
|
||||
if (opt_dest !== undefined) {
|
||||
dest = opt_dest;
|
||||
destOffset = opt_destOffset !== undefined ? opt_destOffset : 0;
|
||||
@@ -22,12 +22,12 @@ _ol_geom_flat_flip_.flipXY = function(flatCoordinates, offset, end, stride, opt_
|
||||
dest = [];
|
||||
destOffset = 0;
|
||||
}
|
||||
var j = offset;
|
||||
let j = offset;
|
||||
while (j < end) {
|
||||
var x = flatCoordinates[j++];
|
||||
const x = flatCoordinates[j++];
|
||||
dest[destOffset++] = flatCoordinates[j++];
|
||||
dest[destOffset++] = x;
|
||||
for (var k = 2; k < stride; ++k) {
|
||||
for (let k = 2; k < stride; ++k) {
|
||||
dest[destOffset++] = flatCoordinates[j++];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import {squaredSegmentDistance, toRadians, toDegrees} from '../../math.js';
|
||||
import {get as getProjection, getTransform} from '../../proj.js';
|
||||
var _ol_geom_flat_geodesic_ = {};
|
||||
const _ol_geom_flat_geodesic_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,26 +19,26 @@ _ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredToleranc
|
||||
// FIXME optimize stack operations
|
||||
|
||||
/** @type {Array.<number>} */
|
||||
var flatCoordinates = [];
|
||||
const flatCoordinates = [];
|
||||
|
||||
var geoA = interpolate(0);
|
||||
var geoB = interpolate(1);
|
||||
let geoA = interpolate(0);
|
||||
let geoB = interpolate(1);
|
||||
|
||||
var a = transform(geoA);
|
||||
var b = transform(geoB);
|
||||
let a = transform(geoA);
|
||||
let b = transform(geoB);
|
||||
|
||||
/** @type {Array.<ol.Coordinate>} */
|
||||
var geoStack = [geoB, geoA];
|
||||
const geoStack = [geoB, geoA];
|
||||
/** @type {Array.<ol.Coordinate>} */
|
||||
var stack = [b, a];
|
||||
const stack = [b, a];
|
||||
/** @type {Array.<number>} */
|
||||
var fractionStack = [1, 0];
|
||||
const fractionStack = [1, 0];
|
||||
|
||||
/** @type {Object.<string, boolean>} */
|
||||
var fractions = {};
|
||||
const fractions = {};
|
||||
|
||||
var maxIterations = 1e5;
|
||||
var geoM, m, fracA, fracB, fracM, key;
|
||||
let maxIterations = 1e5;
|
||||
let geoM, m, fracA, fracB, fracM, key;
|
||||
|
||||
while (--maxIterations > 0 && fractionStack.length > 0) {
|
||||
// Pop the a coordinate off the stack
|
||||
@@ -60,7 +60,7 @@ _ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredToleranc
|
||||
geoM = interpolate(fracM);
|
||||
m = transform(geoM);
|
||||
if (squaredSegmentDistance(m[0], m[1], a[0], a[1],
|
||||
b[0], b[1]) < squaredTolerance) {
|
||||
b[0], b[1]) < squaredTolerance) {
|
||||
// If the m point is sufficiently close to the straight line, then we
|
||||
// discard it. Just use the b coordinate and move on to the next line
|
||||
// segment.
|
||||
@@ -91,39 +91,39 @@ _ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredToleranc
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
_ol_geom_flat_geodesic_.greatCircleArc = function(
|
||||
lon1, lat1, lon2, lat2, projection, squaredTolerance) {
|
||||
lon1, lat1, lon2, lat2, projection, squaredTolerance) {
|
||||
|
||||
var geoProjection = getProjection('EPSG:4326');
|
||||
const geoProjection = getProjection('EPSG:4326');
|
||||
|
||||
var cosLat1 = Math.cos(toRadians(lat1));
|
||||
var sinLat1 = Math.sin(toRadians(lat1));
|
||||
var cosLat2 = Math.cos(toRadians(lat2));
|
||||
var sinLat2 = Math.sin(toRadians(lat2));
|
||||
var cosDeltaLon = Math.cos(toRadians(lon2 - lon1));
|
||||
var sinDeltaLon = Math.sin(toRadians(lon2 - lon1));
|
||||
var d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon;
|
||||
const cosLat1 = Math.cos(toRadians(lat1));
|
||||
const sinLat1 = Math.sin(toRadians(lat1));
|
||||
const cosLat2 = Math.cos(toRadians(lat2));
|
||||
const sinLat2 = Math.sin(toRadians(lat2));
|
||||
const cosDeltaLon = Math.cos(toRadians(lon2 - lon1));
|
||||
const sinDeltaLon = Math.sin(toRadians(lon2 - lon1));
|
||||
const d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon;
|
||||
|
||||
return _ol_geom_flat_geodesic_.line_(
|
||||
/**
|
||||
/**
|
||||
* @param {number} frac Fraction.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
function(frac) {
|
||||
if (1 <= d) {
|
||||
return [lon2, lat2];
|
||||
}
|
||||
var D = frac * Math.acos(d);
|
||||
var cosD = Math.cos(D);
|
||||
var sinD = Math.sin(D);
|
||||
var y = sinDeltaLon * cosLat2;
|
||||
var x = cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosDeltaLon;
|
||||
var theta = Math.atan2(y, x);
|
||||
var lat = Math.asin(sinLat1 * cosD + cosLat1 * sinD * Math.cos(theta));
|
||||
var lon = toRadians(lon1) +
|
||||
function(frac) {
|
||||
if (1 <= d) {
|
||||
return [lon2, lat2];
|
||||
}
|
||||
const D = frac * Math.acos(d);
|
||||
const cosD = Math.cos(D);
|
||||
const sinD = Math.sin(D);
|
||||
const y = sinDeltaLon * cosLat2;
|
||||
const x = cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosDeltaLon;
|
||||
const theta = Math.atan2(y, x);
|
||||
const lat = Math.asin(sinLat1 * cosD + cosLat1 * sinD * Math.cos(theta));
|
||||
const lon = toRadians(lon1) +
|
||||
Math.atan2(Math.sin(theta) * sinD * cosLat1,
|
||||
cosD - sinLat1 * Math.sin(lat));
|
||||
return [toDegrees(lon), toDegrees(lat)];
|
||||
}, getTransform(geoProjection, projection), squaredTolerance);
|
||||
cosD - sinLat1 * Math.sin(lat));
|
||||
return [toDegrees(lon), toDegrees(lat)];
|
||||
}, getTransform(geoProjection, projection), squaredTolerance);
|
||||
};
|
||||
|
||||
|
||||
@@ -137,16 +137,16 @@ _ol_geom_flat_geodesic_.greatCircleArc = function(
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
_ol_geom_flat_geodesic_.meridian = function(lon, lat1, lat2, projection, squaredTolerance) {
|
||||
var epsg4326Projection = getProjection('EPSG:4326');
|
||||
const epsg4326Projection = getProjection('EPSG:4326');
|
||||
return _ol_geom_flat_geodesic_.line_(
|
||||
/**
|
||||
/**
|
||||
* @param {number} frac Fraction.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
function(frac) {
|
||||
return [lon, lat1 + ((lat2 - lat1) * frac)];
|
||||
},
|
||||
getTransform(epsg4326Projection, projection), squaredTolerance);
|
||||
function(frac) {
|
||||
return [lon, lat1 + ((lat2 - lat1) * frac)];
|
||||
},
|
||||
getTransform(epsg4326Projection, projection), squaredTolerance);
|
||||
};
|
||||
|
||||
|
||||
@@ -160,15 +160,15 @@ _ol_geom_flat_geodesic_.meridian = function(lon, lat1, lat2, projection, squared
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
_ol_geom_flat_geodesic_.parallel = function(lat, lon1, lon2, projection, squaredTolerance) {
|
||||
var epsg4326Projection = getProjection('EPSG:4326');
|
||||
const epsg4326Projection = getProjection('EPSG:4326');
|
||||
return _ol_geom_flat_geodesic_.line_(
|
||||
/**
|
||||
/**
|
||||
* @param {number} frac Fraction.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
function(frac) {
|
||||
return [lon1 + ((lon2 - lon1) * frac), lat];
|
||||
},
|
||||
getTransform(epsg4326Projection, projection), squaredTolerance);
|
||||
function(frac) {
|
||||
return [lon1 + ((lon2 - lon1) * frac), lat];
|
||||
},
|
||||
getTransform(epsg4326Projection, projection), squaredTolerance);
|
||||
};
|
||||
export default _ol_geom_flat_geodesic_;
|
||||
|
||||
+14
-14
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/inflate
|
||||
*/
|
||||
var _ol_geom_flat_inflate_ = {};
|
||||
const _ol_geom_flat_inflate_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,9 +13,9 @@ var _ol_geom_flat_inflate_ = {};
|
||||
* @return {Array.<ol.Coordinate>} Coordinates.
|
||||
*/
|
||||
_ol_geom_flat_inflate_.coordinates = function(flatCoordinates, offset, end, stride, opt_coordinates) {
|
||||
var coordinates = opt_coordinates !== undefined ? opt_coordinates : [];
|
||||
var i = 0;
|
||||
var j;
|
||||
const coordinates = opt_coordinates !== undefined ? opt_coordinates : [];
|
||||
let i = 0;
|
||||
let j;
|
||||
for (j = offset; j < end; j += stride) {
|
||||
coordinates[i++] = flatCoordinates.slice(j, j + stride);
|
||||
}
|
||||
@@ -33,13 +33,13 @@ _ol_geom_flat_inflate_.coordinates = function(flatCoordinates, offset, end, stri
|
||||
* @return {Array.<Array.<ol.Coordinate>>} Coordinatess.
|
||||
*/
|
||||
_ol_geom_flat_inflate_.coordinatess = function(flatCoordinates, offset, ends, stride, opt_coordinatess) {
|
||||
var coordinatess = opt_coordinatess !== undefined ? opt_coordinatess : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
const coordinatess = opt_coordinatess !== undefined ? opt_coordinatess : [];
|
||||
let i = 0;
|
||||
let j, jj;
|
||||
for (j = 0, jj = ends.length; j < jj; ++j) {
|
||||
var end = ends[j];
|
||||
const end = ends[j];
|
||||
coordinatess[i++] = _ol_geom_flat_inflate_.coordinates(
|
||||
flatCoordinates, offset, end, stride, coordinatess[i]);
|
||||
flatCoordinates, offset, end, stride, coordinatess[i]);
|
||||
offset = end;
|
||||
}
|
||||
coordinatess.length = i;
|
||||
@@ -57,13 +57,13 @@ _ol_geom_flat_inflate_.coordinatess = function(flatCoordinates, offset, ends, st
|
||||
* @return {Array.<Array.<Array.<ol.Coordinate>>>} Coordinatesss.
|
||||
*/
|
||||
_ol_geom_flat_inflate_.coordinatesss = function(flatCoordinates, offset, endss, stride, opt_coordinatesss) {
|
||||
var coordinatesss = opt_coordinatesss !== undefined ? opt_coordinatesss : [];
|
||||
var i = 0;
|
||||
var j, jj;
|
||||
const coordinatesss = opt_coordinatesss !== undefined ? opt_coordinatesss : [];
|
||||
let i = 0;
|
||||
let j, jj;
|
||||
for (j = 0, jj = endss.length; j < jj; ++j) {
|
||||
var ends = endss[j];
|
||||
const ends = endss[j];
|
||||
coordinatesss[i++] = _ol_geom_flat_inflate_.coordinatess(
|
||||
flatCoordinates, offset, ends, stride, coordinatesss[i]);
|
||||
flatCoordinates, offset, ends, stride, coordinatesss[i]);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
coordinatesss.length = i;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import {numberSafeCompareFunction} from '../../array.js';
|
||||
import _ol_geom_flat_contains_ from '../flat/contains.js';
|
||||
var _ol_geom_flat_interiorpoint_ = {};
|
||||
const _ol_geom_flat_interiorpoint_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,14 +20,14 @@ var _ol_geom_flat_interiorpoint_ = {};
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
_ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset,
|
||||
ends, stride, flatCenters, flatCentersOffset, opt_dest) {
|
||||
var i, ii, x, x1, x2, y1, y2;
|
||||
var y = flatCenters[flatCentersOffset + 1];
|
||||
ends, stride, flatCenters, flatCentersOffset, opt_dest) {
|
||||
let i, ii, x, x1, x2, y1, y2;
|
||||
const y = flatCenters[flatCentersOffset + 1];
|
||||
/** @type {Array.<number>} */
|
||||
var intersections = [];
|
||||
const intersections = [];
|
||||
// Calculate intersections with the horizontal line
|
||||
for (var r = 0, rr = ends.length; r < rr; ++r) {
|
||||
var end = ends[r];
|
||||
for (let r = 0, rr = ends.length; r < rr; ++r) {
|
||||
const end = ends[r];
|
||||
x1 = flatCoordinates[end - stride];
|
||||
y1 = flatCoordinates[end - stride + 1];
|
||||
for (i = offset; i < end; i += stride) {
|
||||
@@ -43,17 +43,17 @@ _ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset,
|
||||
}
|
||||
// Find the longest segment of the horizontal line that has its center point
|
||||
// inside the linear ring.
|
||||
var pointX = NaN;
|
||||
var maxSegmentLength = -Infinity;
|
||||
let pointX = NaN;
|
||||
let maxSegmentLength = -Infinity;
|
||||
intersections.sort(numberSafeCompareFunction);
|
||||
x1 = intersections[0];
|
||||
for (i = 1, ii = intersections.length; i < ii; ++i) {
|
||||
x2 = intersections[i];
|
||||
var segmentLength = Math.abs(x2 - x1);
|
||||
const segmentLength = Math.abs(x2 - x1);
|
||||
if (segmentLength > maxSegmentLength) {
|
||||
x = (x1 + x2) / 2;
|
||||
if (_ol_geom_flat_contains_.linearRingsContainsXY(
|
||||
flatCoordinates, offset, ends, stride, x, y)) {
|
||||
flatCoordinates, offset, ends, stride, x, y)) {
|
||||
pointX = x;
|
||||
maxSegmentLength = segmentLength;
|
||||
}
|
||||
@@ -84,12 +84,12 @@ _ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset,
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
_ol_geom_flat_interiorpoint_.linearRingss = function(flatCoordinates, offset, endss, stride, flatCenters) {
|
||||
var interiorPoints = [];
|
||||
var i, ii;
|
||||
let interiorPoints = [];
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
interiorPoints = _ol_geom_flat_interiorpoint_.linearRings(flatCoordinates,
|
||||
offset, ends, stride, flatCenters, 2 * i, interiorPoints);
|
||||
offset, ends, stride, flatCenters, 2 * i, interiorPoints);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return interiorPoints;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import {binarySearch} from '../../array.js';
|
||||
import {lerp} from '../../math.js';
|
||||
var _ol_geom_flat_interpolate_ = {};
|
||||
const _ol_geom_flat_interpolate_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,9 +16,9 @@ var _ol_geom_flat_interpolate_ = {};
|
||||
* @return {Array.<number>} Destination.
|
||||
*/
|
||||
_ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, stride, fraction, opt_dest) {
|
||||
var pointX = NaN;
|
||||
var pointY = NaN;
|
||||
var n = (end - offset) / stride;
|
||||
let pointX = NaN;
|
||||
let pointY = NaN;
|
||||
const n = (end - offset) / stride;
|
||||
if (n === 1) {
|
||||
pointX = flatCoordinates[offset];
|
||||
pointY = flatCoordinates[offset + 1];
|
||||
@@ -28,29 +28,29 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s
|
||||
pointY = (1 - fraction) * flatCoordinates[offset + 1] +
|
||||
fraction * flatCoordinates[offset + stride + 1];
|
||||
} else if (n !== 0) {
|
||||
var x1 = flatCoordinates[offset];
|
||||
var y1 = flatCoordinates[offset + 1];
|
||||
var length = 0;
|
||||
var cumulativeLengths = [0];
|
||||
var i;
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
let length = 0;
|
||||
const cumulativeLengths = [0];
|
||||
let i;
|
||||
for (i = offset + stride; i < end; i += stride) {
|
||||
var x2 = flatCoordinates[i];
|
||||
var y2 = flatCoordinates[i + 1];
|
||||
const x2 = flatCoordinates[i];
|
||||
const y2 = flatCoordinates[i + 1];
|
||||
length += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
||||
cumulativeLengths.push(length);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
var target = fraction * length;
|
||||
var index = binarySearch(cumulativeLengths, target);
|
||||
const target = fraction * length;
|
||||
const index = binarySearch(cumulativeLengths, target);
|
||||
if (index < 0) {
|
||||
var t = (target - cumulativeLengths[-index - 2]) /
|
||||
const t = (target - cumulativeLengths[-index - 2]) /
|
||||
(cumulativeLengths[-index - 1] - cumulativeLengths[-index - 2]);
|
||||
var o = offset + (-index - 2) * stride;
|
||||
const o = offset + (-index - 2) * stride;
|
||||
pointX = lerp(
|
||||
flatCoordinates[o], flatCoordinates[o + stride], t);
|
||||
flatCoordinates[o], flatCoordinates[o + stride], t);
|
||||
pointY = lerp(
|
||||
flatCoordinates[o + 1], flatCoordinates[o + stride + 1], t);
|
||||
flatCoordinates[o + 1], flatCoordinates[o + stride + 1], t);
|
||||
} else {
|
||||
pointX = flatCoordinates[offset + index * stride];
|
||||
pointY = flatCoordinates[offset + index * stride + 1];
|
||||
@@ -79,7 +79,7 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o
|
||||
if (end == offset) {
|
||||
return null;
|
||||
}
|
||||
var coordinate;
|
||||
let coordinate;
|
||||
if (m < flatCoordinates[offset + stride - 1]) {
|
||||
if (extrapolate) {
|
||||
coordinate = flatCoordinates.slice(offset, offset + stride);
|
||||
@@ -101,27 +101,27 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o
|
||||
if (m == flatCoordinates[offset + stride - 1]) {
|
||||
return flatCoordinates.slice(offset, offset + stride);
|
||||
}
|
||||
var lo = offset / stride;
|
||||
var hi = end / stride;
|
||||
let lo = offset / stride;
|
||||
let hi = end / stride;
|
||||
while (lo < hi) {
|
||||
var mid = (lo + hi) >> 1;
|
||||
const mid = (lo + hi) >> 1;
|
||||
if (m < flatCoordinates[(mid + 1) * stride - 1]) {
|
||||
hi = mid;
|
||||
} else {
|
||||
lo = mid + 1;
|
||||
}
|
||||
}
|
||||
var m0 = flatCoordinates[lo * stride - 1];
|
||||
const m0 = flatCoordinates[lo * stride - 1];
|
||||
if (m == m0) {
|
||||
return flatCoordinates.slice((lo - 1) * stride, (lo - 1) * stride + stride);
|
||||
}
|
||||
var m1 = flatCoordinates[(lo + 1) * stride - 1];
|
||||
var t = (m - m0) / (m1 - m0);
|
||||
const m1 = flatCoordinates[(lo + 1) * stride - 1];
|
||||
const t = (m - m0) / (m1 - m0);
|
||||
coordinate = [];
|
||||
var i;
|
||||
let i;
|
||||
for (i = 0; i < stride - 1; ++i) {
|
||||
coordinate.push(lerp(flatCoordinates[(lo - 1) * stride + i],
|
||||
flatCoordinates[lo * stride + i], t));
|
||||
flatCoordinates[lo * stride + i], t));
|
||||
}
|
||||
coordinate.push(m);
|
||||
return coordinate;
|
||||
@@ -139,12 +139,12 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
_ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function(
|
||||
flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
|
||||
flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
|
||||
if (interpolate) {
|
||||
return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(
|
||||
flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
|
||||
flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
|
||||
}
|
||||
var coordinate;
|
||||
let coordinate;
|
||||
if (m < flatCoordinates[stride - 1]) {
|
||||
if (extrapolate) {
|
||||
coordinate = flatCoordinates.slice(0, stride);
|
||||
@@ -163,9 +163,9 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function(
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const end = ends[i];
|
||||
if (offset == end) {
|
||||
continue;
|
||||
}
|
||||
@@ -173,7 +173,7 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function(
|
||||
return null;
|
||||
} else if (m <= flatCoordinates[end - 1]) {
|
||||
return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(
|
||||
flatCoordinates, offset, end, stride, m, false);
|
||||
flatCoordinates, offset, end, stride, m, false);
|
||||
}
|
||||
offset = end;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import {containsExtent, createEmpty, extendFlatCoordinates, intersects, intersectsSegment} from '../../extent.js';
|
||||
import _ol_geom_flat_contains_ from '../flat/contains.js';
|
||||
import _ol_geom_flat_segments_ from '../flat/segments.js';
|
||||
var _ol_geom_flat_intersectsextent_ = {};
|
||||
const _ol_geom_flat_intersectsextent_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,8 +16,8 @@ var _ol_geom_flat_intersectsextent_ = {};
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
_ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, end, stride, extent) {
|
||||
var coordinatesExtent = extendFlatCoordinates(
|
||||
createEmpty(), flatCoordinates, offset, end, stride);
|
||||
const coordinatesExtent = extendFlatCoordinates(
|
||||
createEmpty(), flatCoordinates, offset, end, stride);
|
||||
if (!intersects(extent, coordinatesExtent)) {
|
||||
return false;
|
||||
}
|
||||
@@ -33,15 +33,15 @@ _ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, e
|
||||
return true;
|
||||
}
|
||||
return _ol_geom_flat_segments_.forEach(flatCoordinates, offset, end, stride,
|
||||
/**
|
||||
/**
|
||||
* @param {ol.Coordinate} point1 Start point.
|
||||
* @param {ol.Coordinate} point2 End point.
|
||||
* @return {boolean} `true` if the segment and the extent intersect,
|
||||
* `false` otherwise.
|
||||
*/
|
||||
function(point1, point2) {
|
||||
return intersectsSegment(extent, point1, point2);
|
||||
});
|
||||
function(point1, point2) {
|
||||
return intersectsSegment(extent, point1, point2);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -54,10 +54,10 @@ _ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, e
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
_ol_geom_flat_intersectsextent_.lineStrings = function(flatCoordinates, offset, ends, stride, extent) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
if (_ol_geom_flat_intersectsextent_.lineString(
|
||||
flatCoordinates, offset, ends[i], stride, extent)) {
|
||||
flatCoordinates, offset, ends[i], stride, extent)) {
|
||||
return true;
|
||||
}
|
||||
offset = ends[i];
|
||||
@@ -76,23 +76,23 @@ _ol_geom_flat_intersectsextent_.lineStrings = function(flatCoordinates, offset,
|
||||
*/
|
||||
_ol_geom_flat_intersectsextent_.linearRing = function(flatCoordinates, offset, end, stride, extent) {
|
||||
if (_ol_geom_flat_intersectsextent_.lineString(
|
||||
flatCoordinates, offset, end, stride, extent)) {
|
||||
flatCoordinates, offset, end, stride, extent)) {
|
||||
return true;
|
||||
}
|
||||
if (_ol_geom_flat_contains_.linearRingContainsXY(
|
||||
flatCoordinates, offset, end, stride, extent[0], extent[1])) {
|
||||
flatCoordinates, offset, end, stride, extent[0], extent[1])) {
|
||||
return true;
|
||||
}
|
||||
if (_ol_geom_flat_contains_.linearRingContainsXY(
|
||||
flatCoordinates, offset, end, stride, extent[0], extent[3])) {
|
||||
flatCoordinates, offset, end, stride, extent[0], extent[3])) {
|
||||
return true;
|
||||
}
|
||||
if (_ol_geom_flat_contains_.linearRingContainsXY(
|
||||
flatCoordinates, offset, end, stride, extent[2], extent[1])) {
|
||||
flatCoordinates, offset, end, stride, extent[2], extent[1])) {
|
||||
return true;
|
||||
}
|
||||
if (_ol_geom_flat_contains_.linearRingContainsXY(
|
||||
flatCoordinates, offset, end, stride, extent[2], extent[3])) {
|
||||
flatCoordinates, offset, end, stride, extent[2], extent[3])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -109,16 +109,16 @@ _ol_geom_flat_intersectsextent_.linearRing = function(flatCoordinates, offset, e
|
||||
*/
|
||||
_ol_geom_flat_intersectsextent_.linearRings = function(flatCoordinates, offset, ends, stride, extent) {
|
||||
if (!_ol_geom_flat_intersectsextent_.linearRing(
|
||||
flatCoordinates, offset, ends[0], stride, extent)) {
|
||||
flatCoordinates, offset, ends[0], stride, extent)) {
|
||||
return false;
|
||||
}
|
||||
if (ends.length === 1) {
|
||||
return true;
|
||||
}
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 1, ii = ends.length; i < ii; ++i) {
|
||||
if (_ol_geom_flat_contains_.linearRingContainsExtent(
|
||||
flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
|
||||
flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -135,11 +135,11 @@ _ol_geom_flat_intersectsextent_.linearRings = function(flatCoordinates, offset,
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
_ol_geom_flat_intersectsextent_.linearRingss = function(flatCoordinates, offset, endss, stride, extent) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
const ends = endss[i];
|
||||
if (_ol_geom_flat_intersectsextent_.linearRings(
|
||||
flatCoordinates, offset, ends, stride, extent)) {
|
||||
flatCoordinates, offset, ends, stride, extent)) {
|
||||
return true;
|
||||
}
|
||||
offset = ends[ends.length - 1];
|
||||
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/length
|
||||
*/
|
||||
var _ol_geom_flat_length_ = {};
|
||||
const _ol_geom_flat_length_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,13 +12,13 @@ var _ol_geom_flat_length_ = {};
|
||||
* @return {number} Length.
|
||||
*/
|
||||
_ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride) {
|
||||
var x1 = flatCoordinates[offset];
|
||||
var y1 = flatCoordinates[offset + 1];
|
||||
var length = 0;
|
||||
var i;
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
let length = 0;
|
||||
let i;
|
||||
for (i = offset + stride; i < end; i += stride) {
|
||||
var x2 = flatCoordinates[i];
|
||||
var y2 = flatCoordinates[i + 1];
|
||||
const x2 = flatCoordinates[i];
|
||||
const y2 = flatCoordinates[i + 1];
|
||||
length += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
@@ -35,10 +35,10 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride
|
||||
* @return {number} Perimeter.
|
||||
*/
|
||||
_ol_geom_flat_length_.linearRing = function(flatCoordinates, offset, end, stride) {
|
||||
var perimeter =
|
||||
let perimeter =
|
||||
_ol_geom_flat_length_.lineString(flatCoordinates, offset, end, stride);
|
||||
var dx = flatCoordinates[end - stride] - flatCoordinates[offset];
|
||||
var dy = flatCoordinates[end - stride + 1] - flatCoordinates[offset + 1];
|
||||
const dx = flatCoordinates[end - stride] - flatCoordinates[offset];
|
||||
const dy = flatCoordinates[end - stride + 1] - flatCoordinates[offset + 1];
|
||||
perimeter += Math.sqrt(dx * dx + dy * dy);
|
||||
return perimeter;
|
||||
};
|
||||
|
||||
+21
-21
@@ -2,7 +2,7 @@
|
||||
* @module ol/geom/flat/orient
|
||||
*/
|
||||
import _ol_geom_flat_reverse_ from '../flat/reverse.js';
|
||||
var _ol_geom_flat_orient_ = {};
|
||||
const _ol_geom_flat_orient_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -15,12 +15,12 @@ var _ol_geom_flat_orient_ = {};
|
||||
_ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset, end, stride) {
|
||||
// http://tinyurl.com/clockwise-method
|
||||
// https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrlinearring.cpp
|
||||
var edge = 0;
|
||||
var x1 = flatCoordinates[end - stride];
|
||||
var y1 = flatCoordinates[end - stride + 1];
|
||||
let edge = 0;
|
||||
let x1 = flatCoordinates[end - stride];
|
||||
let y1 = flatCoordinates[end - stride + 1];
|
||||
for (; offset < end; offset += stride) {
|
||||
var x2 = flatCoordinates[offset];
|
||||
var y2 = flatCoordinates[offset + 1];
|
||||
const x2 = flatCoordinates[offset];
|
||||
const y2 = flatCoordinates[offset + 1];
|
||||
edge += (x2 - x1) * (y2 + y1);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
@@ -43,12 +43,12 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset,
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
_ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) {
|
||||
var right = opt_right !== undefined ? opt_right : false;
|
||||
var i, ii;
|
||||
const right = opt_right !== undefined ? opt_right : false;
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
var isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
const end = ends[i];
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
if (i === 0) {
|
||||
if ((right && isClockwise) || (!right && !isClockwise)) {
|
||||
return false;
|
||||
@@ -78,10 +78,10 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset,
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
_ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
if (!_ol_geom_flat_orient_.linearRingsAreOriented(
|
||||
flatCoordinates, offset, endss[i], stride, opt_right)) {
|
||||
flatCoordinates, offset, endss[i], stride, opt_right)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -103,13 +103,13 @@ _ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset
|
||||
* @return {number} End.
|
||||
*/
|
||||
_ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends, stride, opt_right) {
|
||||
var right = opt_right !== undefined ? opt_right : false;
|
||||
var i, ii;
|
||||
const right = opt_right !== undefined ? opt_right : false;
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
var isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
var reverse = i === 0 ?
|
||||
const end = ends[i];
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
const reverse = i === 0 ?
|
||||
(right && isClockwise) || (!right && !isClockwise) :
|
||||
(right && !isClockwise) || (!right && isClockwise);
|
||||
if (reverse) {
|
||||
@@ -135,10 +135,10 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends
|
||||
* @return {number} End.
|
||||
*/
|
||||
_ol_geom_flat_orient_.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
var i, ii;
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
offset = _ol_geom_flat_orient_.orientLinearRings(
|
||||
flatCoordinates, offset, endss[i], stride, opt_right);
|
||||
flatCoordinates, offset, endss[i], stride, opt_right);
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/reverse
|
||||
*/
|
||||
var _ol_geom_flat_reverse_ = {};
|
||||
const _ol_geom_flat_reverse_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,9 +12,8 @@ var _ol_geom_flat_reverse_ = {};
|
||||
*/
|
||||
_ol_geom_flat_reverse_.coordinates = function(flatCoordinates, offset, end, stride) {
|
||||
while (offset < end - stride) {
|
||||
var i;
|
||||
for (i = 0; i < stride; ++i) {
|
||||
var tmp = flatCoordinates[offset + i];
|
||||
for (let i = 0; i < stride; ++i) {
|
||||
const tmp = flatCoordinates[offset + i];
|
||||
flatCoordinates[offset + i] = flatCoordinates[end - stride + i];
|
||||
flatCoordinates[end - stride + i] = tmp;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/segments
|
||||
*/
|
||||
var _ol_geom_flat_segments_ = {};
|
||||
const _ol_geom_flat_segments_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,9 +20,9 @@ var _ol_geom_flat_segments_ = {};
|
||||
* @template T,S
|
||||
*/
|
||||
_ol_geom_flat_segments_.forEach = function(flatCoordinates, offset, end, stride, callback, opt_this) {
|
||||
var point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]];
|
||||
var point2 = [];
|
||||
var ret;
|
||||
const point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]];
|
||||
const point2 = [];
|
||||
let ret;
|
||||
for (; (offset + stride) < end; offset += stride) {
|
||||
point2[0] = flatCoordinates[offset + stride];
|
||||
point2[1] = flatCoordinates[offset + stride + 1];
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import {squaredSegmentDistance, squaredDistance} from '../../math.js';
|
||||
var _ol_geom_flat_simplify_ = {};
|
||||
const _ol_geom_flat_simplify_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -43,20 +43,20 @@ var _ol_geom_flat_simplify_ = {};
|
||||
* @return {Array.<number>} Simplified line string.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
|
||||
var simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
|
||||
stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
|
||||
const simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
|
||||
opt_simplifiedFlatCoordinates : [];
|
||||
if (!highQuality) {
|
||||
end = _ol_geom_flat_simplify_.radialDistance(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
flatCoordinates = simplifiedFlatCoordinates;
|
||||
offset = 0;
|
||||
stride = 2;
|
||||
}
|
||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker(
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
return simplifiedFlatCoordinates;
|
||||
};
|
||||
|
||||
@@ -73,8 +73,8 @@ _ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end,
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
var n = (end - offset) / stride;
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
const n = (end - offset) / stride;
|
||||
if (n < 3) {
|
||||
for (; offset < end; offset += stride) {
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] =
|
||||
@@ -85,26 +85,26 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
return simplifiedOffset;
|
||||
}
|
||||
/** @type {Array.<number>} */
|
||||
var markers = new Array(n);
|
||||
const markers = new Array(n);
|
||||
markers[0] = 1;
|
||||
markers[n - 1] = 1;
|
||||
/** @type {Array.<number>} */
|
||||
var stack = [offset, end - stride];
|
||||
var index = 0;
|
||||
var i;
|
||||
const stack = [offset, end - stride];
|
||||
let index = 0;
|
||||
let i;
|
||||
while (stack.length > 0) {
|
||||
var last = stack.pop();
|
||||
var first = stack.pop();
|
||||
var maxSquaredDistance = 0;
|
||||
var x1 = flatCoordinates[first];
|
||||
var y1 = flatCoordinates[first + 1];
|
||||
var x2 = flatCoordinates[last];
|
||||
var y2 = flatCoordinates[last + 1];
|
||||
const last = stack.pop();
|
||||
const first = stack.pop();
|
||||
let maxSquaredDistance = 0;
|
||||
const x1 = flatCoordinates[first];
|
||||
const y1 = flatCoordinates[first + 1];
|
||||
const x2 = flatCoordinates[last];
|
||||
const y2 = flatCoordinates[last + 1];
|
||||
for (i = first + stride; i < last; i += stride) {
|
||||
var x = flatCoordinates[i];
|
||||
var y = flatCoordinates[i + 1];
|
||||
var squaredDistance = squaredSegmentDistance(
|
||||
x, y, x1, y1, x2, y2);
|
||||
const x = flatCoordinates[i];
|
||||
const y = flatCoordinates[i + 1];
|
||||
const squaredDistance = squaredSegmentDistance(
|
||||
x, y, x1, y1, x2, y2);
|
||||
if (squaredDistance > maxSquaredDistance) {
|
||||
index = i;
|
||||
maxSquaredDistance = squaredDistance;
|
||||
@@ -145,14 +145,14 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset,
|
||||
ends, stride, squaredTolerance, simplifiedFlatCoordinates,
|
||||
simplifiedOffset, simplifiedEnds) {
|
||||
var i, ii;
|
||||
ends, stride, squaredTolerance, simplifiedFlatCoordinates,
|
||||
simplifiedOffset, simplifiedEnds) {
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const end = ends[i];
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.douglasPeucker(
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
simplifiedEnds.push(simplifiedOffset);
|
||||
offset = end;
|
||||
}
|
||||
@@ -173,15 +173,15 @@ _ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset,
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.douglasPeuckerss = function(
|
||||
flatCoordinates, offset, endss, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
var i, ii;
|
||||
flatCoordinates, offset, endss, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
var simplifiedEnds = [];
|
||||
const ends = endss[i];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.douglasPeuckers(
|
||||
flatCoordinates, offset, ends, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
flatCoordinates, offset, ends, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
simplifiedEndss.push(simplifiedEnds);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
@@ -201,7 +201,7 @@ _ol_geom_flat_simplify_.douglasPeuckerss = function(
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
if (end <= offset + stride) {
|
||||
// zero or one point, no simplification possible, so copy and return
|
||||
for (; offset < end; offset += stride) {
|
||||
@@ -211,13 +211,13 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end,
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
var x1 = flatCoordinates[offset];
|
||||
var y1 = flatCoordinates[offset + 1];
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
// copy first point
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = x1;
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = y1;
|
||||
var x2 = x1;
|
||||
var y2 = y1;
|
||||
let x2 = x1;
|
||||
let y2 = y1;
|
||||
for (offset += stride; offset < end; offset += stride) {
|
||||
x2 = flatCoordinates[offset];
|
||||
y2 = flatCoordinates[offset + 1];
|
||||
@@ -268,21 +268,21 @@ _ol_geom_flat_simplify_.snap = function(value, tolerance) {
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride,
|
||||
tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
// do nothing if the line is empty
|
||||
if (offset == end) {
|
||||
return simplifiedOffset;
|
||||
}
|
||||
// snap the first coordinate (P1)
|
||||
var x1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
var y1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
let x1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
let y1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
offset += stride;
|
||||
// add the first coordinate to the output
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = x1;
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = y1;
|
||||
// find the next coordinate that does not snap to the same value as the first
|
||||
// coordinate (P2)
|
||||
var x2, y2;
|
||||
let x2, y2;
|
||||
do {
|
||||
x2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
y2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
@@ -298,21 +298,20 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride
|
||||
}
|
||||
} while (x2 == x1 && y2 == y1);
|
||||
while (offset < end) {
|
||||
var x3, y3;
|
||||
// snap the next coordinate (P3)
|
||||
x3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
y3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
const x3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
const y3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
offset += stride;
|
||||
// skip P3 if it is equal to P2
|
||||
if (x3 == x2 && y3 == y2) {
|
||||
continue;
|
||||
}
|
||||
// calculate the delta between P1 and P2
|
||||
var dx1 = x2 - x1;
|
||||
var dy1 = y2 - y1;
|
||||
const dx1 = x2 - x1;
|
||||
const dy1 = y2 - y1;
|
||||
// calculate the delta between P3 and P1
|
||||
var dx2 = x3 - x1;
|
||||
var dy2 = y3 - y1;
|
||||
const dx2 = x3 - x1;
|
||||
const dy2 = y3 - y1;
|
||||
// if P1, P2, and P3 are colinear and P3 is further from P1 than P2 is from
|
||||
// P1 in the same direction then P2 is on the straight line between P1 and
|
||||
// P3
|
||||
@@ -354,16 +353,16 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.quantizes = function(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
|
||||
var i, ii;
|
||||
flatCoordinates, offset, ends, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
|
||||
let i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
const end = ends[i];
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.quantize(
|
||||
flatCoordinates, offset, end, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
flatCoordinates, offset, end, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
simplifiedEnds.push(simplifiedOffset);
|
||||
offset = end;
|
||||
}
|
||||
@@ -384,17 +383,17 @@ _ol_geom_flat_simplify_.quantizes = function(
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
_ol_geom_flat_simplify_.quantizess = function(
|
||||
flatCoordinates, offset, endss, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
var i, ii;
|
||||
flatCoordinates, offset, endss, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
let i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
var simplifiedEnds = [];
|
||||
const ends = endss[i];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.quantizes(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
flatCoordinates, offset, ends, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
simplifiedEndss.push(simplifiedEnds);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/straightchunk
|
||||
*/
|
||||
var _ol_geom_flat_straightchunk_ = {};
|
||||
const _ol_geom_flat_straightchunk_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,15 +14,15 @@ var _ol_geom_flat_straightchunk_ = {};
|
||||
* given `flatCoordinates`.
|
||||
*/
|
||||
_ol_geom_flat_straightchunk_.lineString = function(maxAngle, flatCoordinates, offset, end, stride) {
|
||||
var chunkStart = offset;
|
||||
var chunkEnd = offset;
|
||||
var chunkM = 0;
|
||||
var m = 0;
|
||||
var start = offset;
|
||||
var acos, i, m12, m23, x1, y1, x12, y12, x23, y23;
|
||||
let chunkStart = offset;
|
||||
let chunkEnd = offset;
|
||||
let chunkM = 0;
|
||||
let m = 0;
|
||||
let start = offset;
|
||||
let acos, i, m12, m23, x1, y1, x12, y12, x23, y23;
|
||||
for (i = offset; i < end; i += stride) {
|
||||
var x2 = flatCoordinates[i];
|
||||
var y2 = flatCoordinates[i + 1];
|
||||
const x2 = flatCoordinates[i];
|
||||
const y2 = flatCoordinates[i + 1];
|
||||
if (x1 !== undefined) {
|
||||
x23 = x2 - x1;
|
||||
y23 = y2 - y1;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @module ol/geom/flat/textpath
|
||||
*/
|
||||
import {lerp} from '../../math.js';
|
||||
var _ol_geom_flat_textpath_ = {};
|
||||
const _ol_geom_flat_textpath_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,32 +19,32 @@ var _ol_geom_flat_textpath_ = {};
|
||||
* exceeded. Entries of the array are x, y, anchorX, angle, chunk.
|
||||
*/
|
||||
_ol_geom_flat_textpath_.lineString = function(
|
||||
flatCoordinates, offset, end, stride, text, measure, startM, maxAngle) {
|
||||
var result = [];
|
||||
flatCoordinates, offset, end, stride, text, measure, startM, maxAngle) {
|
||||
const result = [];
|
||||
|
||||
// Keep text upright
|
||||
var reverse = flatCoordinates[offset] > flatCoordinates[end - stride];
|
||||
const reverse = flatCoordinates[offset] > flatCoordinates[end - stride];
|
||||
|
||||
var numChars = text.length;
|
||||
const numChars = text.length;
|
||||
|
||||
var x1 = flatCoordinates[offset];
|
||||
var y1 = flatCoordinates[offset + 1];
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
offset += stride;
|
||||
var x2 = flatCoordinates[offset];
|
||||
var y2 = flatCoordinates[offset + 1];
|
||||
var segmentM = 0;
|
||||
var segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
||||
let x2 = flatCoordinates[offset];
|
||||
let y2 = flatCoordinates[offset + 1];
|
||||
let segmentM = 0;
|
||||
let segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
||||
|
||||
var chunk = '';
|
||||
var chunkLength = 0;
|
||||
var data, index, previousAngle;
|
||||
for (var i = 0; i < numChars; ++i) {
|
||||
let chunk = '';
|
||||
let chunkLength = 0;
|
||||
let data, index, previousAngle;
|
||||
for (let i = 0; i < numChars; ++i) {
|
||||
index = reverse ? numChars - i - 1 : i;
|
||||
var char = text.charAt(index);
|
||||
const char = text.charAt(index);
|
||||
chunk = reverse ? char + chunk : chunk + char;
|
||||
var charLength = measure(chunk) - chunkLength;
|
||||
const charLength = measure(chunk) - chunkLength;
|
||||
chunkLength += charLength;
|
||||
var charM = startM + charLength / 2;
|
||||
const charM = startM + charLength / 2;
|
||||
while (offset < end - stride && segmentM + segmentLength < charM) {
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
@@ -54,21 +54,21 @@ _ol_geom_flat_textpath_.lineString = function(
|
||||
segmentM += segmentLength;
|
||||
segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
||||
}
|
||||
var segmentPos = charM - segmentM;
|
||||
var angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
const segmentPos = charM - segmentM;
|
||||
let angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
if (reverse) {
|
||||
angle += angle > 0 ? -Math.PI : Math.PI;
|
||||
}
|
||||
if (previousAngle !== undefined) {
|
||||
var delta = angle - previousAngle;
|
||||
let delta = angle - previousAngle;
|
||||
delta += (delta > Math.PI) ? -2 * Math.PI : (delta < -Math.PI) ? 2 * Math.PI : 0;
|
||||
if (Math.abs(delta) > maxAngle) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var interpolate = segmentPos / segmentLength;
|
||||
var x = lerp(x1, x2, interpolate);
|
||||
var y = lerp(y1, y2, interpolate);
|
||||
const interpolate = segmentPos / segmentLength;
|
||||
const x = lerp(x1, x2, interpolate);
|
||||
const y = lerp(y1, y2, interpolate);
|
||||
if (previousAngle == angle) {
|
||||
if (reverse) {
|
||||
data[0] = x;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @module ol/geom/flat/topology
|
||||
*/
|
||||
import _ol_geom_flat_area_ from '../flat/area.js';
|
||||
var _ol_geom_flat_topology_ = {};
|
||||
const _ol_geom_flat_topology_ = {};
|
||||
|
||||
/**
|
||||
* Check if the linestring is a boundary.
|
||||
@@ -13,7 +13,7 @@ var _ol_geom_flat_topology_ = {};
|
||||
* @return {boolean} The linestring is a boundary.
|
||||
*/
|
||||
_ol_geom_flat_topology_.lineStringIsClosed = function(flatCoordinates, offset, end, stride) {
|
||||
var lastCoord = end - stride;
|
||||
const lastCoord = end - stride;
|
||||
if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
|
||||
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
|
||||
return !!_ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/transform
|
||||
*/
|
||||
var _ol_geom_flat_transform_ = {};
|
||||
const _ol_geom_flat_transform_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,12 +14,12 @@ var _ol_geom_flat_transform_ = {};
|
||||
* @return {Array.<number>} Transformed coordinates.
|
||||
*/
|
||||
_ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) {
|
||||
var dest = opt_dest ? opt_dest : [];
|
||||
var i = 0;
|
||||
var j;
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
let i = 0;
|
||||
let j;
|
||||
for (j = offset; j < end; j += stride) {
|
||||
var x = flatCoordinates[j];
|
||||
var y = flatCoordinates[j + 1];
|
||||
const x = flatCoordinates[j];
|
||||
const y = flatCoordinates[j + 1];
|
||||
dest[i++] = transform[0] * x + transform[2] * y + transform[4];
|
||||
dest[i++] = transform[1] * x + transform[3] * y + transform[5];
|
||||
}
|
||||
@@ -41,18 +41,18 @@ _ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, st
|
||||
* @return {Array.<number>} Transformed coordinates.
|
||||
*/
|
||||
_ol_geom_flat_transform_.rotate = function(flatCoordinates, offset, end, stride, angle, anchor, opt_dest) {
|
||||
var dest = opt_dest ? opt_dest : [];
|
||||
var cos = Math.cos(angle);
|
||||
var sin = Math.sin(angle);
|
||||
var anchorX = anchor[0];
|
||||
var anchorY = anchor[1];
|
||||
var i = 0;
|
||||
for (var j = offset; j < end; j += stride) {
|
||||
var deltaX = flatCoordinates[j] - anchorX;
|
||||
var deltaY = flatCoordinates[j + 1] - anchorY;
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
const anchorX = anchor[0];
|
||||
const anchorY = anchor[1];
|
||||
let i = 0;
|
||||
for (let j = offset; j < end; j += stride) {
|
||||
const deltaX = flatCoordinates[j] - anchorX;
|
||||
const deltaY = flatCoordinates[j + 1] - anchorY;
|
||||
dest[i++] = anchorX + deltaX * cos - deltaY * sin;
|
||||
dest[i++] = anchorY + deltaX * sin + deltaY * cos;
|
||||
for (var k = j + 2; k < j + stride; ++k) {
|
||||
for (let k = j + 2; k < j + stride; ++k) {
|
||||
dest[i++] = flatCoordinates[k];
|
||||
}
|
||||
}
|
||||
@@ -76,16 +76,16 @@ _ol_geom_flat_transform_.rotate = function(flatCoordinates, offset, end, stride,
|
||||
* @return {Array.<number>} Transformed coordinates.
|
||||
*/
|
||||
_ol_geom_flat_transform_.scale = function(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_dest) {
|
||||
var dest = opt_dest ? opt_dest : [];
|
||||
var anchorX = anchor[0];
|
||||
var anchorY = anchor[1];
|
||||
var i = 0;
|
||||
for (var j = offset; j < end; j += stride) {
|
||||
var deltaX = flatCoordinates[j] - anchorX;
|
||||
var deltaY = flatCoordinates[j + 1] - anchorY;
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
const anchorX = anchor[0];
|
||||
const anchorY = anchor[1];
|
||||
let i = 0;
|
||||
for (let j = offset; j < end; j += stride) {
|
||||
const deltaX = flatCoordinates[j] - anchorX;
|
||||
const deltaY = flatCoordinates[j + 1] - anchorY;
|
||||
dest[i++] = anchorX + sx * deltaX;
|
||||
dest[i++] = anchorY + sy * deltaY;
|
||||
for (var k = j + 2; k < j + stride; ++k) {
|
||||
for (let k = j + 2; k < j + stride; ++k) {
|
||||
dest[i++] = flatCoordinates[k];
|
||||
}
|
||||
}
|
||||
@@ -107,9 +107,9 @@ _ol_geom_flat_transform_.scale = function(flatCoordinates, offset, end, stride,
|
||||
* @return {Array.<number>} Transformed coordinates.
|
||||
*/
|
||||
_ol_geom_flat_transform_.translate = function(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) {
|
||||
var dest = opt_dest ? opt_dest : [];
|
||||
var i = 0;
|
||||
var j, k;
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
let i = 0;
|
||||
let j, k;
|
||||
for (j = offset; j < end; j += stride) {
|
||||
dest[i++] = flatCoordinates[j] + deltaX;
|
||||
dest[i++] = flatCoordinates[j + 1] + deltaY;
|
||||
|
||||
Reference in New Issue
Block a user