Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/area
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -24,7 +23,6 @@ export function linearRing(flatCoordinates, offset, end, stride) {
|
||||
return twiceArea / 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -42,7 +40,6 @@ export function linearRings(flatCoordinates, offset, ends, stride) {
|
||||
return area;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {createEmpty, createOrUpdateFromFlatCoordinates} from '../../extent.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -16,7 +15,12 @@ export function linearRingss(flatCoordinates, offset, endss, stride) {
|
||||
let extent = createEmpty();
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
extent = createOrUpdateFromFlatCoordinates(flatCoordinates, offset, ends[0], stride);
|
||||
extent = createOrUpdateFromFlatCoordinates(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends[0],
|
||||
stride
|
||||
);
|
||||
flatCenters.push((extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
|
||||
+122
-35
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {lerp, squaredDistance as squaredDx} from '../../math.js';
|
||||
|
||||
|
||||
/**
|
||||
* Returns the point on the 2D line segment flatCoordinates[offset1] to
|
||||
* flatCoordinates[offset2] that is closest to the point (x, y). Extra
|
||||
@@ -16,7 +15,15 @@ import {lerp, squaredDistance as squaredDx} from '../../math.js';
|
||||
* @param {number} y Y.
|
||||
* @param {Array<number>} closestPoint Closest point.
|
||||
*/
|
||||
function assignClosest(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) {
|
||||
function assignClosest(
|
||||
flatCoordinates,
|
||||
offset1,
|
||||
offset2,
|
||||
stride,
|
||||
x,
|
||||
y,
|
||||
closestPoint
|
||||
) {
|
||||
const x1 = flatCoordinates[offset1];
|
||||
const y1 = flatCoordinates[offset1 + 1];
|
||||
const dx = flatCoordinates[offset2] - x1;
|
||||
@@ -30,8 +37,11 @@ function assignClosest(flatCoordinates, offset1, offset2, stride, x, y, closestP
|
||||
offset = offset2;
|
||||
} else if (t > 0) {
|
||||
for (let i = 0; i < stride; ++i) {
|
||||
closestPoint[i] = lerp(flatCoordinates[offset1 + i],
|
||||
flatCoordinates[offset2 + i], t);
|
||||
closestPoint[i] = lerp(
|
||||
flatCoordinates[offset1 + i],
|
||||
flatCoordinates[offset2 + i],
|
||||
t
|
||||
);
|
||||
}
|
||||
closestPoint.length = stride;
|
||||
return;
|
||||
@@ -45,7 +55,6 @@ function assignClosest(flatCoordinates, offset1, offset2, stride, x, y, closestP
|
||||
closestPoint.length = stride;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the squared of the largest distance between any pair of consecutive
|
||||
* coordinates.
|
||||
@@ -72,7 +81,6 @@ export function maxSquaredDelta(flatCoordinates, offset, end, stride, max) {
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -81,17 +89,21 @@ export function maxSquaredDelta(flatCoordinates, offset, end, stride, max) {
|
||||
* @param {number} max Max squared delta.
|
||||
* @return {number} Max squared delta.
|
||||
*/
|
||||
export function arrayMaxSquaredDelta(flatCoordinates, offset, ends, stride, max) {
|
||||
export function arrayMaxSquaredDelta(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
max
|
||||
) {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
max = maxSquaredDelta(
|
||||
flatCoordinates, offset, end, stride, max);
|
||||
max = maxSquaredDelta(flatCoordinates, offset, end, stride, max);
|
||||
offset = end;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -100,17 +112,21 @@ export function arrayMaxSquaredDelta(flatCoordinates, offset, ends, stride, max)
|
||||
* @param {number} max Max squared delta.
|
||||
* @return {number} Max squared delta.
|
||||
*/
|
||||
export function multiArrayMaxSquaredDelta(flatCoordinates, offset, endss, stride, max) {
|
||||
export function multiArrayMaxSquaredDelta(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
max
|
||||
) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
max = arrayMaxSquaredDelta(
|
||||
flatCoordinates, offset, ends, stride, max);
|
||||
max = arrayMaxSquaredDelta(flatCoordinates, offset, ends, stride, max);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -125,9 +141,19 @@ export function multiArrayMaxSquaredDelta(flatCoordinates, offset, endss, stride
|
||||
* @param {Array<number>=} opt_tmpPoint Temporary point object.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
export function assignClosestPoint(flatCoordinates, offset, end,
|
||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
export function assignClosestPoint(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
maxDelta,
|
||||
isRing,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance,
|
||||
opt_tmpPoint
|
||||
) {
|
||||
if (offset == end) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
@@ -135,7 +161,11 @@ export function assignClosestPoint(flatCoordinates, offset, end,
|
||||
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];
|
||||
@@ -150,7 +180,14 @@ export function assignClosestPoint(flatCoordinates, offset, end,
|
||||
let index = offset + stride;
|
||||
while (index < end) {
|
||||
assignClosest(
|
||||
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;
|
||||
@@ -170,15 +207,27 @@ export function assignClosestPoint(flatCoordinates, offset, end,
|
||||
// least (10 - 3) / 2 == 3 (rounded down) points to have any chance of
|
||||
// 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(minSquaredDistance)) / maxDelta) | 0, 1);
|
||||
index +=
|
||||
stride *
|
||||
Math.max(
|
||||
((Math.sqrt(squaredDistance) - Math.sqrt(minSquaredDistance)) /
|
||||
maxDelta) |
|
||||
0,
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isRing) {
|
||||
// Check the closing segment.
|
||||
assignClosest(
|
||||
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;
|
||||
@@ -191,7 +240,6 @@ export function assignClosestPoint(flatCoordinates, offset, end,
|
||||
return minSquaredDistance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -206,21 +254,40 @@ export function assignClosestPoint(flatCoordinates, offset, end,
|
||||
* @param {Array<number>=} opt_tmpPoint Temporary point object.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
export function assignClosestArrayPoint(flatCoordinates, offset, ends,
|
||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
export function assignClosestArrayPoint(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
maxDelta,
|
||||
isRing,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance,
|
||||
opt_tmpPoint
|
||||
) {
|
||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
minSquaredDistance = assignClosestPoint(
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -235,15 +302,35 @@ export function assignClosestArrayPoint(flatCoordinates, offset, ends,
|
||||
* @param {Array<number>=} opt_tmpPoint Temporary point object.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
export function assignClosestMultiArrayPoint(flatCoordinates, offset,
|
||||
endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||
opt_tmpPoint) {
|
||||
export function assignClosestMultiArrayPoint(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
maxDelta,
|
||||
isRing,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance,
|
||||
opt_tmpPoint
|
||||
) {
|
||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
minSquaredDistance = assignClosestArrayPoint(
|
||||
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;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {forEachCorner} from '../../extent.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -12,19 +11,33 @@ import {forEachCorner} from '../../extent.js';
|
||||
* @param {import("../../extent.js").Extent} extent Extent.
|
||||
* @return {boolean} Contains extent.
|
||||
*/
|
||||
export function linearRingContainsExtent(flatCoordinates, offset, end, stride, extent) {
|
||||
const outside = forEachCorner(extent,
|
||||
export function linearRingContainsExtent(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent
|
||||
) {
|
||||
const outside = forEachCorner(
|
||||
extent,
|
||||
/**
|
||||
* @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
function(coordinate) {
|
||||
return !linearRingContainsXY(flatCoordinates, offset, end, stride, coordinate[0], coordinate[1]);
|
||||
});
|
||||
function (coordinate) {
|
||||
return !linearRingContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
coordinate[0],
|
||||
coordinate[1]
|
||||
);
|
||||
}
|
||||
);
|
||||
return !outside;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -34,7 +47,14 @@ export function linearRingContainsExtent(flatCoordinates, offset, end, stride, e
|
||||
* @param {number} y Y.
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
export function linearRingContainsXY(flatCoordinates, offset, end, stride, x, y) {
|
||||
export function linearRingContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
x,
|
||||
y
|
||||
) {
|
||||
// http://geomalgorithms.com/a03-_inclusion.html
|
||||
// Copyright 2000 softSurfer, 2012 Dan Sunday
|
||||
// This code may be freely used and modified for any purpose
|
||||
@@ -49,10 +69,10 @@ export function linearRingContainsXY(flatCoordinates, offset, end, stride, x, y)
|
||||
const x2 = flatCoordinates[offset];
|
||||
const y2 = flatCoordinates[offset + 1];
|
||||
if (y1 <= y) {
|
||||
if (y2 > y && ((x2 - x1) * (y - y1)) - ((x - x1) * (y2 - y1)) > 0) {
|
||||
if (y2 > y && (x2 - x1) * (y - y1) - (x - x1) * (y2 - y1) > 0) {
|
||||
wn++;
|
||||
}
|
||||
} else if (y2 <= y && ((x2 - x1) * (y - y1)) - ((x - x1) * (y2 - y1)) < 0) {
|
||||
} else if (y2 <= y && (x2 - x1) * (y - y1) - (x - x1) * (y2 - y1) < 0) {
|
||||
wn--;
|
||||
}
|
||||
x1 = x2;
|
||||
@@ -61,7 +81,6 @@ export function linearRingContainsXY(flatCoordinates, offset, end, stride, x, y)
|
||||
return wn !== 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -71,7 +90,14 @@ export function linearRingContainsXY(flatCoordinates, offset, end, stride, x, y)
|
||||
* @param {number} y Y.
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
export function linearRingsContainsXY(flatCoordinates, offset, ends, stride, x, y) {
|
||||
export function linearRingsContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
x,
|
||||
y
|
||||
) {
|
||||
if (ends.length === 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -79,14 +105,15 @@ export function linearRingsContainsXY(flatCoordinates, offset, ends, stride, x,
|
||||
return false;
|
||||
}
|
||||
for (let i = 1, ii = ends.length; i < ii; ++i) {
|
||||
if (linearRingContainsXY(flatCoordinates, ends[i - 1], ends[i], stride, x, y)) {
|
||||
if (
|
||||
linearRingContainsXY(flatCoordinates, ends[i - 1], ends[i], stride, x, y)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -96,7 +123,14 @@ export function linearRingsContainsXY(flatCoordinates, offset, ends, stride, x,
|
||||
* @param {number} y Y.
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
export function linearRingssContainsXY(flatCoordinates, offset, endss, stride, x, y) {
|
||||
export function linearRingssContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
x,
|
||||
y
|
||||
) {
|
||||
if (endss.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/deflate
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -17,7 +16,6 @@ export function deflateCoordinate(flatCoordinates, offset, coordinate, stride) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -25,7 +23,12 @@ export function deflateCoordinate(flatCoordinates, offset, coordinate, stride) {
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} offset Offset.
|
||||
*/
|
||||
export function deflateCoordinates(flatCoordinates, offset, coordinates, stride) {
|
||||
export function deflateCoordinates(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
coordinates,
|
||||
stride
|
||||
) {
|
||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
const coordinate = coordinates[i];
|
||||
for (let j = 0; j < stride; ++j) {
|
||||
@@ -35,7 +38,6 @@ export function deflateCoordinates(flatCoordinates, offset, coordinates, stride)
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -44,12 +46,22 @@ export function deflateCoordinates(flatCoordinates, offset, coordinates, stride)
|
||||
* @param {Array<number>=} opt_ends Ends.
|
||||
* @return {Array<number>} Ends.
|
||||
*/
|
||||
export function deflateCoordinatesArray(flatCoordinates, offset, coordinatess, stride, opt_ends) {
|
||||
export function deflateCoordinatesArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
coordinatess,
|
||||
stride,
|
||||
opt_ends
|
||||
) {
|
||||
const ends = opt_ends ? opt_ends : [];
|
||||
let i = 0;
|
||||
for (let j = 0, jj = coordinatess.length; j < jj; ++j) {
|
||||
const end = deflateCoordinates(
|
||||
flatCoordinates, offset, coordinatess[j], stride);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
coordinatess[j],
|
||||
stride
|
||||
);
|
||||
ends[i++] = end;
|
||||
offset = end;
|
||||
}
|
||||
@@ -57,7 +69,6 @@ export function deflateCoordinatesArray(flatCoordinates, offset, coordinatess, s
|
||||
return ends;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -66,12 +77,23 @@ export function deflateCoordinatesArray(flatCoordinates, offset, coordinatess, s
|
||||
* @param {Array<Array<number>>=} opt_endss Endss.
|
||||
* @return {Array<Array<number>>} Endss.
|
||||
*/
|
||||
export function deflateMultiCoordinatesArray(flatCoordinates, offset, coordinatesss, stride, opt_endss) {
|
||||
export function deflateMultiCoordinatesArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
coordinatesss,
|
||||
stride,
|
||||
opt_endss
|
||||
) {
|
||||
const endss = opt_endss ? opt_endss : [];
|
||||
let i = 0;
|
||||
for (let j = 0, jj = coordinatesss.length; j < jj; ++j) {
|
||||
const ends = deflateCoordinatesArray(
|
||||
flatCoordinates, offset, coordinatesss[j], stride, endss[i]);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
coordinatesss[j],
|
||||
stride,
|
||||
endss[i]
|
||||
);
|
||||
endss[i++] = ends;
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/flip
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -12,7 +11,14 @@
|
||||
* @param {number=} opt_destOffset Destination offset.
|
||||
* @return {Array<number>} Flat coordinates.
|
||||
*/
|
||||
export function flipXY(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) {
|
||||
export function flipXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
opt_dest,
|
||||
opt_destOffset
|
||||
) {
|
||||
let dest, destOffset;
|
||||
if (opt_dest !== undefined) {
|
||||
dest = opt_dest;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/**
|
||||
* @module ol/geom/flat/geodesic
|
||||
*/
|
||||
import {squaredSegmentDistance, toRadians, toDegrees} from '../../math.js';
|
||||
import {get as getProjection, getTransform} from '../../proj.js';
|
||||
|
||||
import {squaredSegmentDistance, toDegrees, toRadians} from '../../math.js';
|
||||
|
||||
/**
|
||||
* @param {function(number): import("../../coordinate.js").Coordinate} interpolate Interpolate function.
|
||||
@@ -57,8 +56,10 @@ function line(interpolate, transform, squaredTolerance) {
|
||||
fracM = (fracA + fracB) / 2;
|
||||
geoM = interpolate(fracM);
|
||||
m = transform(geoM);
|
||||
if (squaredSegmentDistance(m[0], m[1], a[0], a[1],
|
||||
b[0], b[1]) < squaredTolerance) {
|
||||
if (
|
||||
squaredSegmentDistance(m[0], m[1], a[0], a[1], 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.
|
||||
@@ -77,7 +78,6 @@ function line(interpolate, transform, squaredTolerance) {
|
||||
return flatCoordinates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a great-circle arcs between two lat/lon points.
|
||||
* @param {number} lon1 Longitude 1 in degrees.
|
||||
@@ -88,7 +88,14 @@ function line(interpolate, transform, squaredTolerance) {
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {Array<number>} Flat coordinates.
|
||||
*/
|
||||
export function greatCircleArc(lon1, lat1, lon2, lat2, projection, squaredTolerance) {
|
||||
export function greatCircleArc(
|
||||
lon1,
|
||||
lat1,
|
||||
lon2,
|
||||
lat2,
|
||||
projection,
|
||||
squaredTolerance
|
||||
) {
|
||||
const geoProjection = getProjection('EPSG:4326');
|
||||
|
||||
const cosLat1 = Math.cos(toRadians(lat1));
|
||||
@@ -104,7 +111,7 @@ export function greatCircleArc(lon1, lat1, lon2, lat2, projection, squaredTolera
|
||||
* @param {number} frac Fraction.
|
||||
* @return {import("../../coordinate.js").Coordinate} Coordinate.
|
||||
*/
|
||||
function(frac) {
|
||||
function (frac) {
|
||||
if (1 <= d) {
|
||||
return [lon2, lat2];
|
||||
}
|
||||
@@ -115,14 +122,19 @@ export function greatCircleArc(lon1, lat1, lon2, lat2, projection, squaredTolera
|
||||
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));
|
||||
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);
|
||||
},
|
||||
getTransform(geoProjection, projection),
|
||||
squaredTolerance
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a meridian (line at constant longitude).
|
||||
* @param {number} lon Longitude.
|
||||
@@ -139,13 +151,14 @@ export function meridian(lon, lat1, lat2, projection, squaredTolerance) {
|
||||
* @param {number} frac Fraction.
|
||||
* @return {import("../../coordinate.js").Coordinate} Coordinate.
|
||||
*/
|
||||
function(frac) {
|
||||
return [lon, lat1 + ((lat2 - lat1) * frac)];
|
||||
function (frac) {
|
||||
return [lon, lat1 + (lat2 - lat1) * frac];
|
||||
},
|
||||
getTransform(epsg4326Projection, projection), squaredTolerance);
|
||||
getTransform(epsg4326Projection, projection),
|
||||
squaredTolerance
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a parallel (line at constant latitude).
|
||||
* @param {number} lat Latitude.
|
||||
@@ -162,8 +175,10 @@ export function parallel(lat, lon1, lon2, projection, squaredTolerance) {
|
||||
* @param {number} frac Fraction.
|
||||
* @return {import("../../coordinate.js").Coordinate} Coordinate.
|
||||
*/
|
||||
function(frac) {
|
||||
return [lon1 + ((lon2 - lon1) * frac), lat];
|
||||
function (frac) {
|
||||
return [lon1 + (lon2 - lon1) * frac, lat];
|
||||
},
|
||||
getTransform(epsg4326Projection, projection), squaredTolerance);
|
||||
getTransform(epsg4326Projection, projection),
|
||||
squaredTolerance
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/inflate
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -11,7 +10,13 @@
|
||||
* @param {Array<import("../../coordinate.js").Coordinate>=} opt_coordinates Coordinates.
|
||||
* @return {Array<import("../../coordinate.js").Coordinate>} Coordinates.
|
||||
*/
|
||||
export function inflateCoordinates(flatCoordinates, offset, end, stride, opt_coordinates) {
|
||||
export function inflateCoordinates(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
opt_coordinates
|
||||
) {
|
||||
const coordinates = opt_coordinates !== undefined ? opt_coordinates : [];
|
||||
let i = 0;
|
||||
for (let j = offset; j < end; j += stride) {
|
||||
@@ -21,7 +26,6 @@ export function inflateCoordinates(flatCoordinates, offset, end, stride, opt_coo
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -30,20 +34,30 @@ export function inflateCoordinates(flatCoordinates, offset, end, stride, opt_coo
|
||||
* @param {Array<Array<import("../../coordinate.js").Coordinate>>=} opt_coordinatess Coordinatess.
|
||||
* @return {Array<Array<import("../../coordinate.js").Coordinate>>} Coordinatess.
|
||||
*/
|
||||
export function inflateCoordinatesArray(flatCoordinates, offset, ends, stride, opt_coordinatess) {
|
||||
export function inflateCoordinatesArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
opt_coordinatess
|
||||
) {
|
||||
const coordinatess = opt_coordinatess !== undefined ? opt_coordinatess : [];
|
||||
let i = 0;
|
||||
for (let j = 0, jj = ends.length; j < jj; ++j) {
|
||||
const end = ends[j];
|
||||
coordinatess[i++] = inflateCoordinates(
|
||||
flatCoordinates, offset, end, stride, coordinatess[i]);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
coordinatess[i]
|
||||
);
|
||||
offset = end;
|
||||
}
|
||||
coordinatess.length = i;
|
||||
return coordinatess;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -53,13 +67,25 @@ export function inflateCoordinatesArray(flatCoordinates, offset, ends, stride, o
|
||||
* Coordinatesss.
|
||||
* @return {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} Coordinatesss.
|
||||
*/
|
||||
export function inflateMultiCoordinatesArray(flatCoordinates, offset, endss, stride, opt_coordinatesss) {
|
||||
const coordinatesss = opt_coordinatesss !== undefined ? opt_coordinatesss : [];
|
||||
export function inflateMultiCoordinatesArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
opt_coordinatesss
|
||||
) {
|
||||
const coordinatesss =
|
||||
opt_coordinatesss !== undefined ? opt_coordinatesss : [];
|
||||
let i = 0;
|
||||
for (let j = 0, jj = endss.length; j < jj; ++j) {
|
||||
const ends = endss[j];
|
||||
coordinatesss[i++] = inflateCoordinatesArray(
|
||||
flatCoordinates, offset, ends, stride, coordinatesss[i]);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
coordinatesss[i]
|
||||
);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
coordinatesss.length = i;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/**
|
||||
* @module ol/geom/flat/interiorpoint
|
||||
*/
|
||||
import {numberSafeCompareFunction} from '../../array.js';
|
||||
import {linearRingsContainsXY} from './contains.js';
|
||||
|
||||
import {numberSafeCompareFunction} from '../../array.js';
|
||||
|
||||
/**
|
||||
* Calculates a point that is likely to lie in the interior of the linear rings.
|
||||
@@ -18,8 +17,15 @@ import {linearRingsContainsXY} from './contains.js';
|
||||
* @return {Array<number>} Destination point as XYM coordinate, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
export function getInteriorPointOfArray(flatCoordinates, offset,
|
||||
ends, stride, flatCenters, flatCentersOffset, opt_dest) {
|
||||
export function getInteriorPointOfArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
flatCenters,
|
||||
flatCentersOffset,
|
||||
opt_dest
|
||||
) {
|
||||
let i, ii, x, x1, x2, y1, y2;
|
||||
const y = flatCenters[flatCentersOffset + 1];
|
||||
/** @type {Array<number>} */
|
||||
@@ -33,7 +39,7 @@ export function getInteriorPointOfArray(flatCoordinates, offset,
|
||||
x2 = flatCoordinates[i];
|
||||
y2 = flatCoordinates[i + 1];
|
||||
if ((y <= y1 && y2 <= y) || (y1 <= y && y <= y2)) {
|
||||
x = (y - y1) / (y2 - y1) * (x2 - x1) + x1;
|
||||
x = ((y - y1) / (y2 - y1)) * (x2 - x1) + x1;
|
||||
intersections.push(x);
|
||||
}
|
||||
x1 = x2;
|
||||
@@ -71,7 +77,6 @@ export function getInteriorPointOfArray(flatCoordinates, offset,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -81,12 +86,25 @@ export function getInteriorPointOfArray(flatCoordinates, offset,
|
||||
* @return {Array<number>} Interior points as XYM coordinates, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
export function getInteriorPointsOfMultiArray(flatCoordinates, offset, endss, stride, flatCenters) {
|
||||
export function getInteriorPointsOfMultiArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
flatCenters
|
||||
) {
|
||||
let interiorPoints = [];
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
interiorPoints = getInteriorPointOfArray(flatCoordinates,
|
||||
offset, ends, stride, flatCenters, 2 * i, interiorPoints);
|
||||
interiorPoints = getInteriorPointOfArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
flatCenters,
|
||||
2 * i,
|
||||
interiorPoints
|
||||
);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return interiorPoints;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import {binarySearch} from '../../array.js';
|
||||
import {lerp} from '../../math.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -14,7 +13,14 @@ import {lerp} from '../../math.js';
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @return {Array<number>} Destination.
|
||||
*/
|
||||
export function interpolatePoint(flatCoordinates, offset, end, stride, fraction, opt_dest) {
|
||||
export function interpolatePoint(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
fraction,
|
||||
opt_dest
|
||||
) {
|
||||
let pointX = NaN;
|
||||
let pointY = NaN;
|
||||
const n = (end - offset) / stride;
|
||||
@@ -22,10 +28,12 @@ export function interpolatePoint(flatCoordinates, offset, end, stride, fraction,
|
||||
pointX = flatCoordinates[offset];
|
||||
pointY = flatCoordinates[offset + 1];
|
||||
} else if (n == 2) {
|
||||
pointX = (1 - fraction) * flatCoordinates[offset] +
|
||||
fraction * flatCoordinates[offset + stride];
|
||||
pointY = (1 - fraction) * flatCoordinates[offset + 1] +
|
||||
fraction * flatCoordinates[offset + stride + 1];
|
||||
pointX =
|
||||
(1 - fraction) * flatCoordinates[offset] +
|
||||
fraction * flatCoordinates[offset + stride];
|
||||
pointY =
|
||||
(1 - fraction) * flatCoordinates[offset + 1] +
|
||||
fraction * flatCoordinates[offset + stride + 1];
|
||||
} else if (n !== 0) {
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
@@ -42,13 +50,12 @@ export function interpolatePoint(flatCoordinates, offset, end, stride, fraction,
|
||||
const target = fraction * length;
|
||||
const index = binarySearch(cumulativeLengths, target);
|
||||
if (index < 0) {
|
||||
const t = (target - cumulativeLengths[-index - 2]) /
|
||||
(cumulativeLengths[-index - 1] - cumulativeLengths[-index - 2]);
|
||||
const t =
|
||||
(target - cumulativeLengths[-index - 2]) /
|
||||
(cumulativeLengths[-index - 1] - cumulativeLengths[-index - 2]);
|
||||
const o = offset + (-index - 2) * stride;
|
||||
pointX = lerp(
|
||||
flatCoordinates[o], flatCoordinates[o + stride], t);
|
||||
pointY = lerp(
|
||||
flatCoordinates[o + 1], flatCoordinates[o + stride + 1], t);
|
||||
pointX = lerp(flatCoordinates[o], flatCoordinates[o + stride], t);
|
||||
pointY = lerp(flatCoordinates[o + 1], flatCoordinates[o + stride + 1], t);
|
||||
} else {
|
||||
pointX = flatCoordinates[offset + index * stride];
|
||||
pointY = flatCoordinates[offset + index * stride + 1];
|
||||
@@ -63,7 +70,6 @@ export function interpolatePoint(flatCoordinates, offset, end, stride, fraction,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -73,7 +79,14 @@ export function interpolatePoint(flatCoordinates, offset, end, stride, fraction,
|
||||
* @param {boolean} extrapolate Extrapolate.
|
||||
* @return {import("../../coordinate.js").Coordinate} Coordinate.
|
||||
*/
|
||||
export function lineStringCoordinateAtM(flatCoordinates, offset, end, stride, m, extrapolate) {
|
||||
export function lineStringCoordinateAtM(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
m,
|
||||
extrapolate
|
||||
) {
|
||||
if (end == offset) {
|
||||
return null;
|
||||
}
|
||||
@@ -117,14 +130,18 @@ export function lineStringCoordinateAtM(flatCoordinates, offset, end, stride, m,
|
||||
const t = (m - m0) / (m1 - m0);
|
||||
coordinate = [];
|
||||
for (let i = 0; i < stride - 1; ++i) {
|
||||
coordinate.push(lerp(flatCoordinates[(lo - 1) * stride + i],
|
||||
flatCoordinates[lo * stride + i], t));
|
||||
coordinate.push(
|
||||
lerp(
|
||||
flatCoordinates[(lo - 1) * stride + i],
|
||||
flatCoordinates[lo * stride + i],
|
||||
t
|
||||
)
|
||||
);
|
||||
}
|
||||
coordinate.push(m);
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -136,10 +153,23 @@ export function lineStringCoordinateAtM(flatCoordinates, offset, end, stride, m,
|
||||
* @return {import("../../coordinate.js").Coordinate} Coordinate.
|
||||
*/
|
||||
export function lineStringsCoordinateAtM(
|
||||
flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
m,
|
||||
extrapolate,
|
||||
interpolate
|
||||
) {
|
||||
if (interpolate) {
|
||||
return lineStringCoordinateAtM(
|
||||
flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends[ends.length - 1],
|
||||
stride,
|
||||
m,
|
||||
extrapolate
|
||||
);
|
||||
}
|
||||
let coordinate;
|
||||
if (m < flatCoordinates[stride - 1]) {
|
||||
@@ -169,7 +199,13 @@ export function lineStringsCoordinateAtM(
|
||||
return null;
|
||||
} else if (m <= flatCoordinates[end - 1]) {
|
||||
return lineStringCoordinateAtM(
|
||||
flatCoordinates, offset, end, stride, m, false);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
m,
|
||||
false
|
||||
);
|
||||
}
|
||||
offset = end;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
/**
|
||||
* @module ol/geom/flat/intersectsextent
|
||||
*/
|
||||
import {containsExtent, createEmpty, extendFlatCoordinates, intersects, intersectsSegment} from '../../extent.js';
|
||||
import {linearRingContainsXY, linearRingContainsExtent} from './contains.js';
|
||||
import {
|
||||
containsExtent,
|
||||
createEmpty,
|
||||
extendFlatCoordinates,
|
||||
intersects,
|
||||
intersectsSegment,
|
||||
} from '../../extent.js';
|
||||
import {forEach as forEachSegment} from './segments.js';
|
||||
|
||||
import {linearRingContainsExtent, linearRingContainsXY} from './contains.js';
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
@@ -14,36 +19,49 @@ import {forEach as forEachSegment} from './segments.js';
|
||||
* @param {import("../../extent.js").Extent} extent Extent.
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
export function intersectsLineString(flatCoordinates, offset, end, stride, extent) {
|
||||
export function intersectsLineString(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent
|
||||
) {
|
||||
const coordinatesExtent = extendFlatCoordinates(
|
||||
createEmpty(), flatCoordinates, offset, end, stride);
|
||||
createEmpty(),
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride
|
||||
);
|
||||
if (!intersects(extent, coordinatesExtent)) {
|
||||
return false;
|
||||
}
|
||||
if (containsExtent(extent, coordinatesExtent)) {
|
||||
return true;
|
||||
}
|
||||
if (coordinatesExtent[0] >= extent[0] &&
|
||||
coordinatesExtent[2] <= extent[2]) {
|
||||
if (coordinatesExtent[0] >= extent[0] && coordinatesExtent[2] <= extent[2]) {
|
||||
return true;
|
||||
}
|
||||
if (coordinatesExtent[1] >= extent[1] &&
|
||||
coordinatesExtent[3] <= extent[3]) {
|
||||
if (coordinatesExtent[1] >= extent[1] && coordinatesExtent[3] <= extent[3]) {
|
||||
return true;
|
||||
}
|
||||
return forEachSegment(flatCoordinates, offset, end, stride,
|
||||
return forEachSegment(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
/**
|
||||
* @param {import("../../coordinate.js").Coordinate} point1 Start point.
|
||||
* @param {import("../../coordinate.js").Coordinate} point2 End point.
|
||||
* @return {boolean} `true` if the segment and the extent intersect,
|
||||
* `false` otherwise.
|
||||
*/
|
||||
function(point1, point2) {
|
||||
function (point1, point2) {
|
||||
return intersectsSegment(extent, point1, point2);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -52,10 +70,17 @@ export function intersectsLineString(flatCoordinates, offset, end, stride, exten
|
||||
* @param {import("../../extent.js").Extent} extent Extent.
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
export function intersectsLineStringArray(flatCoordinates, offset, ends, stride, extent) {
|
||||
export function intersectsLineStringArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
extent
|
||||
) {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
if (intersectsLineString(
|
||||
flatCoordinates, offset, ends[i], stride, extent)) {
|
||||
if (
|
||||
intersectsLineString(flatCoordinates, offset, ends[i], stride, extent)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
offset = ends[i];
|
||||
@@ -63,7 +88,6 @@ export function intersectsLineStringArray(flatCoordinates, offset, ends, stride,
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -72,27 +96,67 @@ export function intersectsLineStringArray(flatCoordinates, offset, ends, stride,
|
||||
* @param {import("../../extent.js").Extent} extent Extent.
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
export function intersectsLinearRing(flatCoordinates, offset, end, stride, extent) {
|
||||
if (intersectsLineString(
|
||||
flatCoordinates, offset, end, stride, extent)) {
|
||||
export function intersectsLinearRing(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent
|
||||
) {
|
||||
if (intersectsLineString(flatCoordinates, offset, end, stride, extent)) {
|
||||
return true;
|
||||
}
|
||||
if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[0], extent[1])) {
|
||||
if (
|
||||
linearRingContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent[0],
|
||||
extent[1]
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[0], extent[3])) {
|
||||
if (
|
||||
linearRingContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent[0],
|
||||
extent[3]
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[2], extent[1])) {
|
||||
if (
|
||||
linearRingContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent[2],
|
||||
extent[1]
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[2], extent[3])) {
|
||||
if (
|
||||
linearRingContainsXY(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
extent[2],
|
||||
extent[3]
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -101,17 +165,38 @@ export function intersectsLinearRing(flatCoordinates, offset, end, stride, exten
|
||||
* @param {import("../../extent.js").Extent} extent Extent.
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
export function intersectsLinearRingArray(flatCoordinates, offset, ends, stride, extent) {
|
||||
if (!intersectsLinearRing(
|
||||
flatCoordinates, offset, ends[0], stride, extent)) {
|
||||
export function intersectsLinearRingArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
extent
|
||||
) {
|
||||
if (!intersectsLinearRing(flatCoordinates, offset, ends[0], stride, extent)) {
|
||||
return false;
|
||||
}
|
||||
if (ends.length === 1) {
|
||||
return true;
|
||||
}
|
||||
for (let i = 1, ii = ends.length; i < ii; ++i) {
|
||||
if (linearRingContainsExtent(flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
|
||||
if (!intersectsLineString(flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
|
||||
if (
|
||||
linearRingContainsExtent(
|
||||
flatCoordinates,
|
||||
ends[i - 1],
|
||||
ends[i],
|
||||
stride,
|
||||
extent
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!intersectsLineString(
|
||||
flatCoordinates,
|
||||
ends[i - 1],
|
||||
ends[i],
|
||||
stride,
|
||||
extent
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -119,7 +204,6 @@ export function intersectsLinearRingArray(flatCoordinates, offset, ends, stride,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -128,11 +212,18 @@ export function intersectsLinearRingArray(flatCoordinates, offset, ends, stride,
|
||||
* @param {import("../../extent.js").Extent} extent Extent.
|
||||
* @return {boolean} True if the geometry and the extent intersect.
|
||||
*/
|
||||
export function intersectsLinearRingMultiArray(flatCoordinates, offset, endss, stride, extent) {
|
||||
export function intersectsLinearRingMultiArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
extent
|
||||
) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
if (intersectsLinearRingArray(
|
||||
flatCoordinates, offset, ends, stride, extent)) {
|
||||
if (
|
||||
intersectsLinearRingArray(flatCoordinates, offset, ends, stride, extent)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
offset = ends[ends.length - 1];
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/length
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -24,7 +23,6 @@ export function lineStringLength(flatCoordinates, offset, end, stride) {
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
|
||||
+51
-17
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {coordinates as reverseCoordinates} from './reverse.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -27,7 +26,6 @@ export function linearRingIsClockwise(flatCoordinates, offset, end, stride) {
|
||||
return edge > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if linear rings are oriented. By default, left-hand orientation
|
||||
* is tested (first ring must be clockwise, remaining rings counter-clockwise).
|
||||
@@ -41,12 +39,22 @@ export function linearRingIsClockwise(flatCoordinates, offset, end, stride) {
|
||||
* (counter-clockwise exterior ring and clockwise interior rings).
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
export function linearRingsAreOriented(flatCoordinates, offset, ends, stride, opt_right) {
|
||||
export function linearRingsAreOriented(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
opt_right
|
||||
) {
|
||||
const right = opt_right !== undefined ? opt_right : false;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride
|
||||
);
|
||||
if (i === 0) {
|
||||
if ((right && isClockwise) || (!right && !isClockwise)) {
|
||||
return false;
|
||||
@@ -61,7 +69,6 @@ export function linearRingsAreOriented(flatCoordinates, offset, ends, stride, op
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if linear rings are oriented. By default, left-hand orientation
|
||||
* is tested (first ring must be clockwise, remaining rings counter-clockwise).
|
||||
@@ -75,11 +82,18 @@ export function linearRingsAreOriented(flatCoordinates, offset, ends, stride, op
|
||||
* (counter-clockwise exterior ring and clockwise interior rings).
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
export function linearRingssAreOriented(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
export function linearRingssAreOriented(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
opt_right
|
||||
) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
if (!linearRingsAreOriented(
|
||||
flatCoordinates, offset, ends, stride, opt_right)) {
|
||||
if (
|
||||
!linearRingsAreOriented(flatCoordinates, offset, ends, stride, opt_right)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (ends.length) {
|
||||
@@ -89,7 +103,6 @@ export function linearRingssAreOriented(flatCoordinates, offset, endss, stride,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Orient coordinates in a flat array of linear rings. By default, rings
|
||||
* are oriented following the left-hand rule (clockwise for exterior and
|
||||
@@ -103,15 +116,26 @@ export function linearRingssAreOriented(flatCoordinates, offset, endss, stride,
|
||||
* @param {boolean=} opt_right Follow the right-hand rule for orientation.
|
||||
* @return {number} End.
|
||||
*/
|
||||
export function orientLinearRings(flatCoordinates, offset, ends, stride, opt_right) {
|
||||
export function orientLinearRings(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
opt_right
|
||||
) {
|
||||
const right = opt_right !== undefined ? opt_right : false;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
const reverse = i === 0 ?
|
||||
(right && isClockwise) || (!right && !isClockwise) :
|
||||
(right && !isClockwise) || (!right && isClockwise);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride
|
||||
);
|
||||
const reverse =
|
||||
i === 0
|
||||
? (right && isClockwise) || (!right && !isClockwise)
|
||||
: (right && !isClockwise) || (!right && isClockwise);
|
||||
if (reverse) {
|
||||
reverseCoordinates(flatCoordinates, offset, end, stride);
|
||||
}
|
||||
@@ -120,7 +144,6 @@ export function orientLinearRings(flatCoordinates, offset, ends, stride, opt_rig
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Orient coordinates in a flat array of linear rings. By default, rings
|
||||
* are oriented following the left-hand rule (clockwise for exterior and
|
||||
@@ -134,10 +157,21 @@ export function orientLinearRings(flatCoordinates, offset, ends, stride, opt_rig
|
||||
* @param {boolean=} opt_right Follow the right-hand rule for orientation.
|
||||
* @return {number} End.
|
||||
*/
|
||||
export function orientLinearRingsArray(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
export function orientLinearRingsArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
opt_right
|
||||
) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
offset = orientLinearRings(
|
||||
flatCoordinates, offset, endss[i], stride, opt_right);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss[i],
|
||||
stride,
|
||||
opt_right
|
||||
);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/reverse
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/segments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This function calls `callback` for each segment of the flat coordinates
|
||||
* array. If the callback returns a truthy value the function returns that
|
||||
@@ -20,7 +19,7 @@ export function forEach(flatCoordinates, offset, end, stride, callback) {
|
||||
const point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]];
|
||||
const point2 = [];
|
||||
let ret;
|
||||
for (; (offset + stride) < end; offset += stride) {
|
||||
for (; offset + stride < end; offset += stride) {
|
||||
point2[0] = flatCoordinates[offset + stride];
|
||||
point2[1] = flatCoordinates[offset + stride + 1];
|
||||
ret = callback(point1, point2);
|
||||
|
||||
+136
-53
@@ -27,8 +27,7 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import {squaredSegmentDistance, squaredDistance} from '../../math.js';
|
||||
|
||||
import {squaredDistance, squaredSegmentDistance} from '../../math.js';
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
@@ -41,25 +40,45 @@ import {squaredSegmentDistance, squaredDistance} from '../../math.js';
|
||||
* coordinates.
|
||||
* @return {Array<number>} Simplified line string.
|
||||
*/
|
||||
export function simplifyLineString(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
|
||||
const simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
|
||||
opt_simplifiedFlatCoordinates : [];
|
||||
export function simplifyLineString(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
highQuality,
|
||||
opt_simplifiedFlatCoordinates
|
||||
) {
|
||||
const simplifiedFlatCoordinates =
|
||||
opt_simplifiedFlatCoordinates !== undefined
|
||||
? opt_simplifiedFlatCoordinates
|
||||
: [];
|
||||
if (!highQuality) {
|
||||
end = radialDistance(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
end = radialDistance(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
);
|
||||
flatCoordinates = simplifiedFlatCoordinates;
|
||||
offset = 0;
|
||||
stride = 2;
|
||||
}
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
);
|
||||
return simplifiedFlatCoordinates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -71,15 +90,21 @@ export function simplifyLineString(flatCoordinates, offset, end,
|
||||
* @param {number} simplifiedOffset Simplified offset.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function douglasPeucker(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
export function douglasPeucker(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset
|
||||
) {
|
||||
const n = (end - offset) / stride;
|
||||
if (n < 3) {
|
||||
for (; offset < end; offset += stride) {
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = flatCoordinates[offset];
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] =
|
||||
flatCoordinates[offset];
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] =
|
||||
flatCoordinates[offset + 1];
|
||||
flatCoordinates[offset + 1];
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
@@ -101,8 +126,7 @@ export function douglasPeucker(flatCoordinates, offset, end,
|
||||
for (let i = first + stride; i < last; i += stride) {
|
||||
const x = flatCoordinates[i];
|
||||
const y = flatCoordinates[i + 1];
|
||||
const squaredDistance = squaredSegmentDistance(
|
||||
x, y, x1, y1, x2, y2);
|
||||
const squaredDistance = squaredSegmentDistance(x, y, x1, y1, x2, y2);
|
||||
if (squaredDistance > maxSquaredDistance) {
|
||||
index = i;
|
||||
maxSquaredDistance = squaredDistance;
|
||||
@@ -121,15 +145,14 @@ export function douglasPeucker(flatCoordinates, offset, end,
|
||||
for (let i = 0; i < n; ++i) {
|
||||
if (markers[i]) {
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] =
|
||||
flatCoordinates[offset + i * stride];
|
||||
flatCoordinates[offset + i * stride];
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] =
|
||||
flatCoordinates[offset + i * stride + 1];
|
||||
flatCoordinates[offset + i * stride + 1];
|
||||
}
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -142,21 +165,33 @@ export function douglasPeucker(flatCoordinates, offset, end,
|
||||
* @param {Array<number>} simplifiedEnds Simplified ends.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function douglasPeuckerArray(flatCoordinates, offset,
|
||||
ends, stride, squaredTolerance, simplifiedFlatCoordinates,
|
||||
simplifiedOffset, simplifiedEnds) {
|
||||
export function douglasPeuckerArray(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset,
|
||||
simplifiedEnds
|
||||
) {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
simplifiedOffset = douglasPeucker(
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset
|
||||
);
|
||||
simplifiedEnds.push(simplifiedOffset);
|
||||
offset = end;
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -170,21 +205,34 @@ export function douglasPeuckerArray(flatCoordinates, offset,
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function douglasPeuckerMultiArray(
|
||||
flatCoordinates, offset, endss, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset,
|
||||
simplifiedEndss
|
||||
) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedOffset = douglasPeuckerArray(
|
||||
flatCoordinates, offset, ends, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset,
|
||||
simplifiedEnds
|
||||
);
|
||||
simplifiedEndss.push(simplifiedEnds);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -196,14 +244,21 @@ export function douglasPeuckerMultiArray(
|
||||
* @param {number} simplifiedOffset Simplified offset.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function radialDistance(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
export function radialDistance(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset
|
||||
) {
|
||||
if (end <= offset + stride) {
|
||||
// zero or one point, no simplification possible, so copy and return
|
||||
for (; offset < end; offset += stride) {
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = flatCoordinates[offset];
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] =
|
||||
flatCoordinates[offset + 1];
|
||||
flatCoordinates[offset + 1];
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
@@ -233,7 +288,6 @@ export function radialDistance(flatCoordinates, offset, end,
|
||||
return simplifiedOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} value Value.
|
||||
* @param {number} tolerance Tolerance.
|
||||
@@ -243,7 +297,6 @@ export function snap(value, tolerance) {
|
||||
return tolerance * Math.round(value / tolerance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simplifies a line string using an algorithm designed by Tim Schaub.
|
||||
* Coordinates are snapped to the nearest value in a virtual grid and
|
||||
@@ -263,8 +316,15 @@ export function snap(value, tolerance) {
|
||||
* @param {number} simplifiedOffset Simplified offset.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function quantize(flatCoordinates, offset, end, stride,
|
||||
tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
export function quantize(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset
|
||||
) {
|
||||
// do nothing if the line is empty
|
||||
if (offset == end) {
|
||||
return simplifiedOffset;
|
||||
@@ -311,9 +371,11 @@ export function quantize(flatCoordinates, offset, end, stride,
|
||||
// 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
|
||||
if ((dx1 * dy2 == dy1 * dx2) &&
|
||||
((dx1 < 0 && dx2 < dx1) || dx1 == dx2 || (dx1 > 0 && dx2 > dx1)) &&
|
||||
((dy1 < 0 && dy2 < dy1) || dy1 == dy2 || (dy1 > 0 && dy2 > dy1))) {
|
||||
if (
|
||||
dx1 * dy2 == dy1 * dx2 &&
|
||||
((dx1 < 0 && dx2 < dx1) || dx1 == dx2 || (dx1 > 0 && dx2 > dx1)) &&
|
||||
((dy1 < 0 && dy2 < dy1) || dy1 == dy2 || (dy1 > 0 && dy2 > dy1))
|
||||
) {
|
||||
// discard P2 and set P2 = P3
|
||||
x2 = x3;
|
||||
y2 = y3;
|
||||
@@ -335,7 +397,6 @@ export function quantize(flatCoordinates, offset, end, stride,
|
||||
return simplifiedOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -349,22 +410,32 @@ export function quantize(flatCoordinates, offset, end, stride,
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function quantizeArray(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset,
|
||||
simplifiedEnds
|
||||
) {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
simplifiedOffset = quantize(
|
||||
flatCoordinates, offset, end, stride,
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset
|
||||
);
|
||||
simplifiedEnds.push(simplifiedOffset);
|
||||
offset = end;
|
||||
}
|
||||
return simplifiedOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -378,16 +449,28 @@ export function quantizeArray(
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
export function quantizeMultiArray(
|
||||
flatCoordinates, offset, endss, stride,
|
||||
flatCoordinates,
|
||||
offset,
|
||||
endss,
|
||||
stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset,
|
||||
simplifiedEndss
|
||||
) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedOffset = quantizeArray(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
flatCoordinates,
|
||||
offset,
|
||||
ends,
|
||||
stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
simplifiedFlatCoordinates,
|
||||
simplifiedOffset,
|
||||
simplifiedEnds
|
||||
);
|
||||
simplifiedEndss.push(simplifiedEnds);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/straightchunk
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} maxAngle Maximum acceptable angle delta between segments.
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import {lerp} from '../../math.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Path to put text on.
|
||||
* @param {number} offset Start offset of the `flatCoordinates`.
|
||||
@@ -20,7 +19,18 @@ import {lerp} from '../../math.js';
|
||||
* exceeded). Entries of the array are x, y, anchorX, angle, chunk.
|
||||
*/
|
||||
export function drawTextOnPath(
|
||||
flatCoordinates, offset, end, stride, text, startM, maxAngle, scale, measureAndCacheTextWidth, font, cache) {
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
text,
|
||||
startM,
|
||||
maxAngle,
|
||||
scale,
|
||||
measureAndCacheTextWidth,
|
||||
font,
|
||||
cache
|
||||
) {
|
||||
const result = [];
|
||||
|
||||
// Keep text upright
|
||||
@@ -60,7 +70,8 @@ export function drawTextOnPath(
|
||||
if (previousAngle !== undefined) {
|
||||
let delta = angle - previousAngle;
|
||||
angleChanged = angleChanged || delta !== 0;
|
||||
delta += (delta > Math.PI) ? -2 * Math.PI : (delta < -Math.PI) ? 2 * Math.PI : 0;
|
||||
delta +=
|
||||
delta > Math.PI ? -2 * Math.PI : delta < -Math.PI ? 2 * Math.PI : 0;
|
||||
if (Math.abs(delta) > maxAngle) {
|
||||
return null;
|
||||
}
|
||||
@@ -72,5 +83,7 @@ export function drawTextOnPath(
|
||||
result[index] = [x, y, charLength / 2, angle, char];
|
||||
startM += charLength;
|
||||
}
|
||||
return angleChanged ? result : [[result[0][0], result[0][1], result[0][2], result[0][3], text]];
|
||||
return angleChanged
|
||||
? result
|
||||
: [[result[0][0], result[0][1], result[0][2], result[0][3], text]];
|
||||
}
|
||||
|
||||
@@ -13,8 +13,11 @@ import {linearRing as linearRingArea} from './area.js';
|
||||
*/
|
||||
export function lineStringIsClosed(flatCoordinates, offset, end, stride) {
|
||||
const lastCoord = end - stride;
|
||||
if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
|
||||
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
|
||||
if (
|
||||
flatCoordinates[offset] === flatCoordinates[lastCoord] &&
|
||||
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] &&
|
||||
(end - offset) / stride > 3
|
||||
) {
|
||||
return !!linearRingArea(flatCoordinates, offset, end, stride);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/transform
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -12,7 +11,14 @@
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function transform2D(flatCoordinates, offset, end, stride, transform, opt_dest) {
|
||||
export function transform2D(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
transform,
|
||||
opt_dest
|
||||
) {
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
let i = 0;
|
||||
for (let j = offset; j < end; j += stride) {
|
||||
@@ -27,7 +33,6 @@ export function transform2D(flatCoordinates, offset, end, stride, transform, opt
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -38,7 +43,15 @@ export function transform2D(flatCoordinates, offset, end, stride, transform, opt
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function rotate(flatCoordinates, offset, end, stride, angle, anchor, opt_dest) {
|
||||
export function rotate(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
angle,
|
||||
anchor,
|
||||
opt_dest
|
||||
) {
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
const cos = Math.cos(angle);
|
||||
const sin = Math.sin(angle);
|
||||
@@ -60,7 +73,6 @@ export function rotate(flatCoordinates, offset, end, stride, angle, anchor, opt_
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scale the coordinates.
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
@@ -73,7 +85,16 @@ export function rotate(flatCoordinates, offset, end, stride, angle, anchor, opt_
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function scale(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_dest) {
|
||||
export function scale(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
sx,
|
||||
sy,
|
||||
anchor,
|
||||
opt_dest
|
||||
) {
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
const anchorX = anchor[0];
|
||||
const anchorY = anchor[1];
|
||||
@@ -93,7 +114,6 @@ export function scale(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
@@ -104,7 +124,15 @@ export function scale(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function translate(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) {
|
||||
export function translate(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
deltaX,
|
||||
deltaY,
|
||||
opt_dest
|
||||
) {
|
||||
const dest = opt_dest ? opt_dest : [];
|
||||
let i = 0;
|
||||
for (let j = offset; j < end; j += stride) {
|
||||
|
||||
Reference in New Issue
Block a user