054af09032
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.
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
/**
|
|
* @module ol/geom/flat/straightchunk
|
|
*/
|
|
|
|
/**
|
|
* @param {number} maxAngle Maximum acceptable angle delta between segments.
|
|
* @param {Array<number>} flatCoordinates Flat coordinates.
|
|
* @param {number} offset Offset.
|
|
* @param {number} end End.
|
|
* @param {number} stride Stride.
|
|
* @return {Array<number>} Start and end of the first suitable chunk of the
|
|
* given `flatCoordinates`.
|
|
*/
|
|
export function matchingChunk(maxAngle, flatCoordinates, offset, end, stride) {
|
|
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) {
|
|
const x2 = flatCoordinates[i];
|
|
const y2 = flatCoordinates[i + 1];
|
|
if (x1 !== undefined) {
|
|
x23 = x2 - x1;
|
|
y23 = y2 - y1;
|
|
m23 = Math.sqrt(x23 * x23 + y23 * y23);
|
|
if (x12 !== undefined) {
|
|
m += m12;
|
|
acos = Math.acos((x12 * x23 + y12 * y23) / (m12 * m23));
|
|
if (acos > maxAngle) {
|
|
if (m > chunkM) {
|
|
chunkM = m;
|
|
chunkStart = start;
|
|
chunkEnd = i;
|
|
}
|
|
m = 0;
|
|
start = i - stride;
|
|
}
|
|
}
|
|
m12 = m23;
|
|
x12 = x23;
|
|
y12 = y23;
|
|
}
|
|
x1 = x2;
|
|
y1 = y2;
|
|
}
|
|
m += m23;
|
|
return m > chunkM ? [start, i] : [chunkStart, chunkEnd];
|
|
}
|