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:
+14
-13
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* @module ol/geom/Circle
|
||||
*/
|
||||
import {createOrUpdate, forEachCorner, intersects} from '../extent.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {createOrUpdate, forEachCorner, intersects} from '../extent.js';
|
||||
import {deflateCoordinate} from './flat/deflate.js';
|
||||
import {rotate, translate} from './flat/transform.js';
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Circle geometry.
|
||||
@@ -15,7 +14,6 @@ import {rotate, translate} from './flat/transform.js';
|
||||
* @api
|
||||
*/
|
||||
class Circle extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {!import("../coordinate.js").Coordinate} center Center.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` and no
|
||||
@@ -104,9 +102,12 @@ class Circle extends SimpleGeometry {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const radius = flatCoordinates[this.stride] - flatCoordinates[0];
|
||||
return createOrUpdate(
|
||||
flatCoordinates[0] - radius, flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius, flatCoordinates[1] + radius,
|
||||
extent);
|
||||
flatCoordinates[0] - radius,
|
||||
flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius,
|
||||
flatCoordinates[1] + radius,
|
||||
extent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +159,6 @@ class Circle extends SimpleGeometry {
|
||||
return forEachCorner(extent, this.intersectsCoordinate.bind(this));
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,8 +193,7 @@ class Circle extends SimpleGeometry {
|
||||
}
|
||||
/** @type {Array<number>} */
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
let offset = deflateCoordinate(
|
||||
flatCoordinates, 0, center, this.stride);
|
||||
let offset = deflateCoordinate(flatCoordinates, 0, center, this.stride);
|
||||
flatCoordinates[offset++] = flatCoordinates[0] + radius;
|
||||
for (let i = 1, ii = this.stride; i < ii; ++i) {
|
||||
flatCoordinates[offset++] = flatCoordinates[i];
|
||||
@@ -229,7 +228,9 @@ class Circle extends SimpleGeometry {
|
||||
rotate(angle, anchor) {
|
||||
const center = this.getCenter();
|
||||
const stride = this.getStride();
|
||||
this.setCenter(rotate(center, 0, center.length, stride, angle, anchor, center));
|
||||
this.setCenter(
|
||||
rotate(center, 0, center.length, stride, angle, anchor, center)
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
@@ -243,13 +244,13 @@ class Circle extends SimpleGeometry {
|
||||
translate(deltaX, deltaY) {
|
||||
const center = this.getCenter();
|
||||
const stride = this.getStride();
|
||||
this.setCenter(translate(center, 0, center.length, stride, deltaX, deltaY, center));
|
||||
this.setCenter(
|
||||
translate(center, 0, center.length, stride, deltaX, deltaY, center)
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transform each coordinate of the circle from one coordinate reference system
|
||||
* to another. The geometry is modified in place.
|
||||
|
||||
+49
-26
@@ -1,21 +1,23 @@
|
||||
/**
|
||||
* @module ol/geom/Geometry
|
||||
*/
|
||||
import {abstract} from '../util.js';
|
||||
import BaseObject from '../Object.js';
|
||||
import {createEmpty, getHeight, returnOrUpdate} from '../extent.js';
|
||||
import {transform2D} from './flat/transform.js';
|
||||
import {get as getProjection, getTransform} from '../proj.js';
|
||||
import Units from '../proj/Units.js';
|
||||
import {create as createTransform, compose as composeTransform} from '../transform.js';
|
||||
import {abstract} from '../util.js';
|
||||
import {
|
||||
compose as composeTransform,
|
||||
create as createTransform,
|
||||
} from '../transform.js';
|
||||
import {createEmpty, getHeight, returnOrUpdate} from '../extent.js';
|
||||
import {get as getProjection, getTransform} from '../proj.js';
|
||||
import {memoizeOne} from '../functions.js';
|
||||
import {transform2D} from './flat/transform.js';
|
||||
|
||||
/**
|
||||
* @type {import("../transform.js").Transform}
|
||||
*/
|
||||
const tmpTransform = createTransform();
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -30,7 +32,6 @@ const tmpTransform = createTransform();
|
||||
*/
|
||||
class Geometry extends BaseObject {
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,11 @@ class Geometry extends BaseObject {
|
||||
* @param {import("../proj.js").TransformFunction} [opt_transform] Optional transform function.
|
||||
* @return {Geometry} Simplified geometry.
|
||||
*/
|
||||
this.simplifyTransformedInternal = memoizeOne(function(revision, squaredTolerance, opt_transform) {
|
||||
this.simplifyTransformedInternal = memoizeOne(function (
|
||||
revision,
|
||||
squaredTolerance,
|
||||
opt_transform
|
||||
) {
|
||||
if (!opt_transform) {
|
||||
return this.getSimplifiedGeometry(squaredTolerance);
|
||||
}
|
||||
@@ -73,7 +78,6 @@ class Geometry extends BaseObject {
|
||||
clone.applyTransform(opt_transform);
|
||||
return clone.getSimplifiedGeometry(squaredTolerance);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +88,11 @@ class Geometry extends BaseObject {
|
||||
* @return {Geometry} Simplified geometry.
|
||||
*/
|
||||
simplifyTransformed(squaredTolerance, opt_transform) {
|
||||
return this.simplifyTransformedInternal(this.getRevision(), squaredTolerance, opt_transform);
|
||||
return this.simplifyTransformedInternal(
|
||||
this.getRevision(),
|
||||
squaredTolerance,
|
||||
opt_transform
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,25 +288,40 @@ class Geometry extends BaseObject {
|
||||
transform(source, destination) {
|
||||
/** @type {import("../proj/Projection.js").default} */
|
||||
const sourceProj = getProjection(source);
|
||||
const transformFn = sourceProj.getUnits() == Units.TILE_PIXELS ?
|
||||
function(inCoordinates, outCoordinates, stride) {
|
||||
const pixelExtent = sourceProj.getExtent();
|
||||
const projectedExtent = sourceProj.getWorldExtent();
|
||||
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
||||
composeTransform(tmpTransform,
|
||||
projectedExtent[0], projectedExtent[3],
|
||||
scale, -scale, 0,
|
||||
0, 0);
|
||||
transform2D(inCoordinates, 0, inCoordinates.length, stride,
|
||||
tmpTransform, outCoordinates);
|
||||
return getTransform(sourceProj, destination)(inCoordinates, outCoordinates, stride);
|
||||
} :
|
||||
getTransform(sourceProj, destination);
|
||||
const transformFn =
|
||||
sourceProj.getUnits() == Units.TILE_PIXELS
|
||||
? function (inCoordinates, outCoordinates, stride) {
|
||||
const pixelExtent = sourceProj.getExtent();
|
||||
const projectedExtent = sourceProj.getWorldExtent();
|
||||
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
||||
composeTransform(
|
||||
tmpTransform,
|
||||
projectedExtent[0],
|
||||
projectedExtent[3],
|
||||
scale,
|
||||
-scale,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
transform2D(
|
||||
inCoordinates,
|
||||
0,
|
||||
inCoordinates.length,
|
||||
stride,
|
||||
tmpTransform,
|
||||
outCoordinates
|
||||
);
|
||||
return getTransform(sourceProj, destination)(
|
||||
inCoordinates,
|
||||
outCoordinates,
|
||||
stride
|
||||
);
|
||||
}
|
||||
: getTransform(sourceProj, destination);
|
||||
this.applyTransform(transformFn);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default Geometry;
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
/**
|
||||
* @module ol/geom/GeometryCollection
|
||||
*/
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {createOrUpdateEmpty, closestSquaredDistanceXY, extend, getCenter} from '../extent.js';
|
||||
import Geometry from './Geometry.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import {
|
||||
closestSquaredDistanceXY,
|
||||
createOrUpdateEmpty,
|
||||
extend,
|
||||
getCenter,
|
||||
} from '../extent.js';
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -14,12 +19,10 @@ import GeometryType from './GeometryType.js';
|
||||
* @api
|
||||
*/
|
||||
class GeometryCollection extends Geometry {
|
||||
|
||||
/**
|
||||
* @param {Array<Geometry>=} opt_geometries Geometries.
|
||||
*/
|
||||
constructor(opt_geometries) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -52,9 +55,9 @@ class GeometryCollection extends Geometry {
|
||||
return;
|
||||
}
|
||||
for (let i = 0, ii = this.geometries_.length; i < ii; ++i) {
|
||||
this.changeEventsKeys_.push(listen(
|
||||
this.geometries_[i], EventType.CHANGE,
|
||||
this.changed, this));
|
||||
this.changeEventsKeys_.push(
|
||||
listen(this.geometries_[i], EventType.CHANGE, this.changed, this)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +86,11 @@ class GeometryCollection extends Geometry {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
minSquaredDistance = geometries[i].closestPointXY(
|
||||
x, y, closestPoint, minSquaredDistance);
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance
|
||||
);
|
||||
}
|
||||
return minSquaredDistance;
|
||||
}
|
||||
@@ -142,7 +149,11 @@ class GeometryCollection extends Geometry {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
if (geometries[i].getType() === this.getType()) {
|
||||
geometriesArray = geometriesArray.concat(/** @type {GeometryCollection} */ (geometries[i]).getGeometriesArrayRecursive());
|
||||
geometriesArray = geometriesArray.concat(
|
||||
/** @type {GeometryCollection} */ (geometries[
|
||||
i
|
||||
]).getGeometriesArrayRecursive()
|
||||
);
|
||||
} else {
|
||||
geometriesArray.push(geometries[i]);
|
||||
}
|
||||
@@ -160,9 +171,11 @@ class GeometryCollection extends Geometry {
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
if (
|
||||
squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)
|
||||
) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -171,7 +184,9 @@ class GeometryCollection extends Geometry {
|
||||
let simplified = false;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
const geometry = geometries[i];
|
||||
const simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
|
||||
const simplifiedGeometry = geometry.getSimplifiedGeometry(
|
||||
squaredTolerance
|
||||
);
|
||||
simplifiedGeometries.push(simplifiedGeometry);
|
||||
if (simplifiedGeometry !== geometry) {
|
||||
simplified = true;
|
||||
@@ -316,7 +331,6 @@ class GeometryCollection extends Geometry {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<Geometry>} geometries Geometries.
|
||||
* @return {Array<Geometry>} Cloned geometries.
|
||||
@@ -329,5 +343,4 @@ function cloneGeometries(geometries) {
|
||||
return clonedGeometries;
|
||||
}
|
||||
|
||||
|
||||
export default GeometryCollection;
|
||||
|
||||
@@ -12,5 +12,5 @@ export default {
|
||||
XY: 'XY',
|
||||
XYZ: 'XYZ',
|
||||
XYM: 'XYM',
|
||||
XYZM: 'XYZM'
|
||||
XYZM: 'XYZM',
|
||||
};
|
||||
|
||||
@@ -17,5 +17,5 @@ export default {
|
||||
MULTI_LINE_STRING: 'MultiLineString',
|
||||
MULTI_POLYGON: 'MultiPolygon',
|
||||
GEOMETRY_COLLECTION: 'GeometryCollection',
|
||||
CIRCLE: 'Circle'
|
||||
CIRCLE: 'Circle',
|
||||
};
|
||||
|
||||
+87
-28
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* @module ol/geom/LineString
|
||||
*/
|
||||
import {extend} from '../array.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import {deflateCoordinates} from './flat/deflate.js';
|
||||
import {douglasPeucker} from './flat/simplify.js';
|
||||
import {extend} from '../array.js';
|
||||
import {forEach as forEachSegment} from './flat/segments.js';
|
||||
import {inflateCoordinates} from './flat/inflate.js';
|
||||
import {interpolatePoint, lineStringCoordinateAtM} from './flat/interpolate.js';
|
||||
import {intersectsLineString} from './flat/intersectsextent.js';
|
||||
import {lineStringLength} from './flat/length.js';
|
||||
import {forEach as forEachSegment} from './flat/segments.js';
|
||||
import {douglasPeucker} from './flat/simplify.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -22,14 +22,12 @@ import {douglasPeucker} from './flat/simplify.js';
|
||||
* @api
|
||||
*/
|
||||
class LineString extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` are also accepted.
|
||||
* @param {GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -57,11 +55,16 @@ class LineString extends SimpleGeometry {
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, /** @type {Array<number>} */ (coordinates));
|
||||
this.setFlatCoordinates(
|
||||
opt_layout,
|
||||
/** @type {Array<number>} */ (coordinates)
|
||||
);
|
||||
} else {
|
||||
this.setCoordinates(/** @type {Array<import("../coordinate.js").Coordinate>} */ (coordinates), opt_layout);
|
||||
this.setCoordinates(
|
||||
/** @type {Array<import("../coordinate.js").Coordinate>} */ (coordinates),
|
||||
opt_layout
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,13 +102,29 @@ class LineString extends SimpleGeometry {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDelta_ = Math.sqrt(
|
||||
maxSquaredDelta(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
0
|
||||
)
|
||||
);
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
this.maxDelta_,
|
||||
false,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +139,13 @@ class LineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
forEachSegment(callback) {
|
||||
return forEachSegment(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, callback);
|
||||
return forEachSegment(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,13 +163,21 @@ class LineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getCoordinateAtM(m, opt_extrapolate) {
|
||||
if (this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) {
|
||||
if (
|
||||
this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
return lineStringCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.flatCoordinates.length, this.stride, m, extrapolate);
|
||||
return lineStringCoordinateAtM(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
m,
|
||||
extrapolate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +187,11 @@ class LineString extends SimpleGeometry {
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,8 +206,13 @@ class LineString extends SimpleGeometry {
|
||||
*/
|
||||
getCoordinateAt(fraction, opt_dest) {
|
||||
return interpolatePoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
fraction, opt_dest);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
fraction,
|
||||
opt_dest
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +222,11 @@ class LineString extends SimpleGeometry {
|
||||
*/
|
||||
getLength() {
|
||||
return lineStringLength(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,8 +248,14 @@ class LineString extends SimpleGeometry {
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
);
|
||||
return new LineString(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
|
||||
@@ -224,8 +276,12 @@ class LineString extends SimpleGeometry {
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLineString(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
extent);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
extent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,10 +296,13 @@ class LineString extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default LineString;
|
||||
|
||||
+55
-18
@@ -1,15 +1,15 @@
|
||||
/**
|
||||
* @module ol/geom/LinearRing
|
||||
*/
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {linearRing as linearRingArea} from './flat/area.js';
|
||||
import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import {deflateCoordinates} from './flat/deflate.js';
|
||||
import {inflateCoordinates} from './flat/inflate.js';
|
||||
import {douglasPeucker} from './flat/simplify.js';
|
||||
import {inflateCoordinates} from './flat/inflate.js';
|
||||
import {linearRing as linearRingArea} from './flat/area.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -19,14 +19,12 @@ import {douglasPeucker} from './flat/simplify.js';
|
||||
* @api
|
||||
*/
|
||||
class LinearRing extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` are also accepted.
|
||||
* @param {GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -42,11 +40,16 @@ class LinearRing extends SimpleGeometry {
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, /** @type {Array<number>} */ (coordinates));
|
||||
this.setFlatCoordinates(
|
||||
opt_layout,
|
||||
/** @type {Array<number>} */ (coordinates)
|
||||
);
|
||||
} else {
|
||||
this.setCoordinates(/** @type {Array<import("../coordinate.js").Coordinate>} */ (coordinates), opt_layout);
|
||||
this.setCoordinates(
|
||||
/** @type {Array<import("../coordinate.js").Coordinate>} */ (coordinates),
|
||||
opt_layout
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,13 +73,29 @@ class LinearRing extends SimpleGeometry {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDelta_ = Math.sqrt(
|
||||
maxSquaredDelta(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
0
|
||||
)
|
||||
);
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
this.maxDelta_,
|
||||
true,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +104,12 @@ class LinearRing extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getArea() {
|
||||
return linearRingArea(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
return linearRingArea(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +119,11 @@ class LinearRing extends SimpleGeometry {
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,8 +134,14 @@ class LinearRing extends SimpleGeometry {
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
);
|
||||
return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
|
||||
@@ -142,10 +176,13 @@ class LinearRing extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default LinearRing;
|
||||
|
||||
+104
-32
@@ -1,18 +1,21 @@
|
||||
/**
|
||||
* @module ol/geom/MultiLineString
|
||||
*/
|
||||
import {extend} from '../array.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import LineString from './LineString.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {assignClosestArrayPoint, arrayMaxSquaredDelta} from './flat/closest.js';
|
||||
import {arrayMaxSquaredDelta, assignClosestArrayPoint} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import {deflateCoordinatesArray} from './flat/deflate.js';
|
||||
import {inflateCoordinatesArray} from './flat/inflate.js';
|
||||
import {interpolatePoint, lineStringsCoordinateAtM} from './flat/interpolate.js';
|
||||
import {intersectsLineStringArray} from './flat/intersectsextent.js';
|
||||
import {douglasPeuckerArray} from './flat/simplify.js';
|
||||
import {extend} from '../array.js';
|
||||
import {inflateCoordinatesArray} from './flat/inflate.js';
|
||||
import {
|
||||
interpolatePoint,
|
||||
lineStringsCoordinateAtM,
|
||||
} from './flat/interpolate.js';
|
||||
import {intersectsLineStringArray} from './flat/intersectsextent.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -21,7 +24,6 @@ import {douglasPeuckerArray} from './flat/simplify.js';
|
||||
* @api
|
||||
*/
|
||||
class MultiLineString extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {Array<Array<import("../coordinate.js").Coordinate>|LineString>|Array<number>} coordinates
|
||||
* Coordinates or LineString geometries. (For internal use, flat coordinates in
|
||||
@@ -30,7 +32,6 @@ class MultiLineString extends SimpleGeometry {
|
||||
* @param {Array<number>=} opt_ends Flat coordinate ends for internal use.
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -52,9 +53,15 @@ class MultiLineString extends SimpleGeometry {
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
if (Array.isArray(coordinates[0])) {
|
||||
this.setCoordinates(/** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ (coordinates), opt_layout);
|
||||
this.setCoordinates(
|
||||
/** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ (coordinates),
|
||||
opt_layout
|
||||
);
|
||||
} else if (opt_layout !== undefined && opt_ends) {
|
||||
this.setFlatCoordinates(opt_layout, /** @type {Array<number>} */ (coordinates));
|
||||
this.setFlatCoordinates(
|
||||
opt_layout,
|
||||
/** @type {Array<number>} */ (coordinates)
|
||||
);
|
||||
this.ends_ = opt_ends;
|
||||
} else {
|
||||
let layout = this.getLayout();
|
||||
@@ -72,7 +79,6 @@ class MultiLineString extends SimpleGeometry {
|
||||
this.setFlatCoordinates(layout, flatCoordinates);
|
||||
this.ends_ = ends;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +102,11 @@ class MultiLineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new MultiLineString(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
|
||||
return new MultiLineString(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
this.ends_.slice()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,13 +121,29 @@ class MultiLineString extends SimpleGeometry {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDelta_ = Math.sqrt(
|
||||
arrayMaxSquaredDelta(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
0
|
||||
)
|
||||
);
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestArrayPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
this.maxDelta_,
|
||||
false,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,15 +169,24 @@ class MultiLineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getCoordinateAtM(m, opt_extrapolate, opt_interpolate) {
|
||||
if ((this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) ||
|
||||
this.flatCoordinates.length === 0) {
|
||||
if (
|
||||
(this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) ||
|
||||
this.flatCoordinates.length === 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
const interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
|
||||
return lineStringsCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.ends_, this.stride, m, extrapolate, interpolate);
|
||||
return lineStringsCoordinateAtM(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
m,
|
||||
extrapolate,
|
||||
interpolate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +196,11 @@ class MultiLineString extends SimpleGeometry {
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,8 +220,13 @@ class MultiLineString extends SimpleGeometry {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
return new LineString(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
return new LineString(
|
||||
this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1],
|
||||
this.ends_[index]
|
||||
),
|
||||
this.layout
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +243,10 @@ class MultiLineString extends SimpleGeometry {
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const lineString = new LineString(flatCoordinates.slice(offset, end), layout);
|
||||
const lineString = new LineString(
|
||||
flatCoordinates.slice(offset, end),
|
||||
layout
|
||||
);
|
||||
lineStrings.push(lineString);
|
||||
offset = end;
|
||||
}
|
||||
@@ -218,7 +265,12 @@ class MultiLineString extends SimpleGeometry {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const midpoint = interpolatePoint(
|
||||
flatCoordinates, offset, end, stride, 0.5);
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
0.5
|
||||
);
|
||||
extend(midpoints, midpoint);
|
||||
offset = end;
|
||||
}
|
||||
@@ -234,9 +286,20 @@ class MultiLineString extends SimpleGeometry {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeuckerArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||
return new MultiLineString(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
squaredTolerance,
|
||||
simplifiedFlatCoordinates,
|
||||
0,
|
||||
simplifiedEnds
|
||||
);
|
||||
return new MultiLineString(
|
||||
simplifiedFlatCoordinates,
|
||||
GeometryLayout.XY,
|
||||
simplifiedEnds
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +319,12 @@ class MultiLineString extends SimpleGeometry {
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLineStringArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, extent);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
extent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,11 +339,15 @@ class MultiLineString extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const ends = deflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride,
|
||||
this.ends_
|
||||
);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default MultiLineString;
|
||||
|
||||
+39
-13
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @module ol/geom/MultiPoint
|
||||
*/
|
||||
import {extend} from '../array.js';
|
||||
import {closestSquaredDistanceXY, containsXY} from '../extent.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import Point from './Point.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {closestSquaredDistanceXY, containsXY} from '../extent.js';
|
||||
import {deflateCoordinates} from './flat/deflate.js';
|
||||
import {extend} from '../array.js';
|
||||
import {inflateCoordinates} from './flat/inflate.js';
|
||||
import {squaredDistance as squaredDx} from '../math.js';
|
||||
|
||||
@@ -17,7 +17,6 @@ import {squaredDistance as squaredDx} from '../math.js';
|
||||
* @api
|
||||
*/
|
||||
class MultiPoint extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` are also accepted.
|
||||
@@ -26,9 +25,15 @@ class MultiPoint extends SimpleGeometry {
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
if (opt_layout && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, /** @type {Array<number>} */ (coordinates));
|
||||
this.setFlatCoordinates(
|
||||
opt_layout,
|
||||
/** @type {Array<number>} */ (coordinates)
|
||||
);
|
||||
} else {
|
||||
this.setCoordinates(/** @type {Array<import("../coordinate.js").Coordinate>} */ (coordinates), opt_layout);
|
||||
this.setCoordinates(
|
||||
/** @type {Array<import("../coordinate.js").Coordinate>} */ (coordinates),
|
||||
opt_layout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +57,10 @@ class MultiPoint extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const multiPoint = new MultiPoint(this.flatCoordinates.slice(), this.layout);
|
||||
const multiPoint = new MultiPoint(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout
|
||||
);
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
@@ -71,7 +79,11 @@ class MultiPoint extends SimpleGeometry {
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const squaredDistance = squaredDx(
|
||||
x, y, flatCoordinates[i], flatCoordinates[i + 1]);
|
||||
x,
|
||||
y,
|
||||
flatCoordinates[i],
|
||||
flatCoordinates[i + 1]
|
||||
);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
for (let j = 0; j < stride; ++j) {
|
||||
@@ -90,7 +102,11 @@ class MultiPoint extends SimpleGeometry {
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,12 +116,19 @@ class MultiPoint extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getPoint(index) {
|
||||
const n = !this.flatCoordinates ? 0 : this.flatCoordinates.length / this.stride;
|
||||
const n = !this.flatCoordinates
|
||||
? 0
|
||||
: this.flatCoordinates.length / this.stride;
|
||||
if (index < 0 || n <= index) {
|
||||
return null;
|
||||
}
|
||||
return new Point(this.flatCoordinates.slice(
|
||||
index * this.stride, (index + 1) * this.stride), this.layout);
|
||||
return new Point(
|
||||
this.flatCoordinates.slice(
|
||||
index * this.stride,
|
||||
(index + 1) * this.stride
|
||||
),
|
||||
this.layout
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,10 +189,13 @@ class MultiPoint extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default MultiPoint;
|
||||
|
||||
+132
-42
@@ -1,22 +1,28 @@
|
||||
/**
|
||||
* @module ol/geom/MultiPolygon
|
||||
*/
|
||||
import {extend} from '../array.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import MultiPoint from './MultiPoint.js';
|
||||
import Polygon from './Polygon.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {
|
||||
assignClosestMultiArrayPoint,
|
||||
multiArrayMaxSquaredDelta,
|
||||
} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import {deflateMultiCoordinatesArray} from './flat/deflate.js';
|
||||
import {extend} from '../array.js';
|
||||
import {getInteriorPointsOfMultiArray} from './flat/interiorpoint.js';
|
||||
import {inflateMultiCoordinatesArray} from './flat/inflate.js';
|
||||
import {intersectsLinearRingMultiArray} from './flat/intersectsextent.js';
|
||||
import {
|
||||
linearRingssAreOriented,
|
||||
orientLinearRingsArray,
|
||||
} from './flat/orient.js';
|
||||
import {linearRingss as linearRingssArea} from './flat/area.js';
|
||||
import {linearRingss as linearRingssCenter} from './flat/center.js';
|
||||
import {assignClosestMultiArrayPoint, multiArrayMaxSquaredDelta} from './flat/closest.js';
|
||||
import {linearRingssContainsXY} from './flat/contains.js';
|
||||
import {deflateMultiCoordinatesArray} from './flat/deflate.js';
|
||||
import {inflateMultiCoordinatesArray} from './flat/inflate.js';
|
||||
import {getInteriorPointsOfMultiArray} from './flat/interiorpoint.js';
|
||||
import {intersectsLinearRingMultiArray} from './flat/intersectsextent.js';
|
||||
import {linearRingssAreOriented, orientLinearRingsArray} from './flat/orient.js';
|
||||
import {quantizeMultiArray} from './flat/simplify.js';
|
||||
|
||||
/**
|
||||
@@ -26,7 +32,6 @@ import {quantizeMultiArray} from './flat/simplify.js';
|
||||
* @api
|
||||
*/
|
||||
class MultiPolygon extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {Array<Array<Array<import("../coordinate.js").Coordinate>>|Polygon>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` and `opt_endss` are also accepted.
|
||||
@@ -34,7 +39,6 @@ class MultiPolygon extends SimpleGeometry {
|
||||
* @param {Array<Array<number>>=} opt_endss Array of ends for internal use with flat coordinates.
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_endss) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -102,13 +106,17 @@ class MultiPolygon extends SimpleGeometry {
|
||||
opt_endss = endss;
|
||||
}
|
||||
if (opt_layout !== undefined && opt_endss) {
|
||||
this.setFlatCoordinates(opt_layout, /** @type {Array<number>} */ (coordinates));
|
||||
this.setFlatCoordinates(
|
||||
opt_layout,
|
||||
/** @type {Array<number>} */ (coordinates)
|
||||
);
|
||||
this.endss_ = opt_endss;
|
||||
} else {
|
||||
this.setCoordinates(/** @type {Array<Array<Array<import("../coordinate.js").Coordinate>>>} */ (coordinates),
|
||||
opt_layout);
|
||||
this.setCoordinates(
|
||||
/** @type {Array<Array<Array<import("../coordinate.js").Coordinate>>>} */ (coordinates),
|
||||
opt_layout
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +156,10 @@ class MultiPolygon extends SimpleGeometry {
|
||||
}
|
||||
|
||||
return new MultiPolygon(
|
||||
this.flatCoordinates.slice(), this.layout, newEndss);
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
newEndss
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,13 +174,29 @@ class MultiPolygon extends SimpleGeometry {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(multiArrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, 0));
|
||||
this.maxDelta_ = Math.sqrt(
|
||||
multiArrayMaxSquaredDelta(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
0
|
||||
)
|
||||
);
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestMultiArrayPoint(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
this.maxDelta_,
|
||||
true,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +205,14 @@ class MultiPolygon extends SimpleGeometry {
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
containsXY(x, y) {
|
||||
return linearRingssContainsXY(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
|
||||
return linearRingssContainsXY(
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +221,12 @@ class MultiPolygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getArea() {
|
||||
return linearRingssArea(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
|
||||
return linearRingssArea(
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,13 +247,22 @@ class MultiPolygon extends SimpleGeometry {
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
orientLinearRingsArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride, opt_right);
|
||||
flatCoordinates,
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
opt_right
|
||||
);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
}
|
||||
|
||||
return inflateMultiCoordinatesArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride);
|
||||
flatCoordinates,
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,10 +278,18 @@ class MultiPolygon extends SimpleGeometry {
|
||||
getFlatInteriorPoints() {
|
||||
if (this.flatInteriorPointsRevision_ != this.getRevision()) {
|
||||
const flatCenters = linearRingssCenter(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride
|
||||
);
|
||||
this.flatInteriorPoints_ = getInteriorPointsOfMultiArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
flatCenters);
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
flatCenters
|
||||
);
|
||||
this.flatInteriorPointsRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatInteriorPoints_;
|
||||
@@ -246,7 +302,10 @@ class MultiPolygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getInteriorPoints() {
|
||||
return new MultiPoint(this.getFlatInteriorPoints().slice(), GeometryLayout.XYM);
|
||||
return new MultiPoint(
|
||||
this.getFlatInteriorPoints().slice(),
|
||||
GeometryLayout.XYM
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,14 +314,18 @@ class MultiPolygon extends SimpleGeometry {
|
||||
getOrientedFlatCoordinates() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (linearRingssAreOriented(
|
||||
flatCoordinates, 0, this.endss_, this.stride)) {
|
||||
if (
|
||||
linearRingssAreOriented(flatCoordinates, 0, this.endss_, this.stride)
|
||||
) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
orientLinearRingsArray(
|
||||
this.orientedFlatCoordinates_, 0, this.endss_, this.stride);
|
||||
this.orientedFlatCoordinates_.length = orientLinearRingsArray(
|
||||
this.orientedFlatCoordinates_,
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
@@ -278,10 +341,20 @@ class MultiPolygon extends SimpleGeometry {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEndss = [];
|
||||
simplifiedFlatCoordinates.length = quantizeMultiArray(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride,
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
Math.sqrt(squaredTolerance),
|
||||
simplifiedFlatCoordinates, 0, simplifiedEndss);
|
||||
return new MultiPolygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEndss);
|
||||
simplifiedFlatCoordinates,
|
||||
0,
|
||||
simplifiedEndss
|
||||
);
|
||||
return new MultiPolygon(
|
||||
simplifiedFlatCoordinates,
|
||||
GeometryLayout.XY,
|
||||
simplifiedEndss
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,7 +381,11 @@ class MultiPolygon extends SimpleGeometry {
|
||||
ends[i] -= offset;
|
||||
}
|
||||
}
|
||||
return new Polygon(this.flatCoordinates.slice(offset, end), this.layout, ends);
|
||||
return new Polygon(
|
||||
this.flatCoordinates.slice(offset, end),
|
||||
this.layout,
|
||||
ends
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +407,11 @@ class MultiPolygon extends SimpleGeometry {
|
||||
ends[j] -= offset;
|
||||
}
|
||||
}
|
||||
const polygon = new Polygon(flatCoordinates.slice(offset, end), layout, ends);
|
||||
const polygon = new Polygon(
|
||||
flatCoordinates.slice(offset, end),
|
||||
layout,
|
||||
ends
|
||||
);
|
||||
polygons.push(polygon);
|
||||
offset = end;
|
||||
}
|
||||
@@ -354,7 +435,12 @@ class MultiPolygon extends SimpleGeometry {
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLinearRingMultiArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, extent);
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.endss_,
|
||||
this.stride,
|
||||
extent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,17 +455,21 @@ class MultiPolygon extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const endss = deflateMultiCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride,
|
||||
this.endss_
|
||||
);
|
||||
if (endss.length === 0) {
|
||||
this.flatCoordinates.length = 0;
|
||||
} else {
|
||||
const lastEnds = endss[endss.length - 1];
|
||||
this.flatCoordinates.length = lastEnds.length === 0 ?
|
||||
0 : lastEnds[lastEnds.length - 1];
|
||||
this.flatCoordinates.length =
|
||||
lastEnds.length === 0 ? 0 : lastEnds[lastEnds.length - 1];
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default MultiPolygon;
|
||||
|
||||
+12
-5
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @module ol/geom/Point
|
||||
*/
|
||||
import {createOrUpdateFromCoordinate, containsXY} from '../extent.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {containsXY, createOrUpdateFromCoordinate} from '../extent.js';
|
||||
import {deflateCoordinate} from './flat/deflate.js';
|
||||
import {squaredDistance as squaredDx} from '../math.js';
|
||||
|
||||
@@ -14,7 +14,6 @@ import {squaredDistance as squaredDx} from '../math.js';
|
||||
* @api
|
||||
*/
|
||||
class Point extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {import("../coordinate.js").Coordinate} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
@@ -43,7 +42,12 @@ class Point extends SimpleGeometry {
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const squaredDistance = squaredDx(x, y, flatCoordinates[0], flatCoordinates[1]);
|
||||
const squaredDistance = squaredDx(
|
||||
x,
|
||||
y,
|
||||
flatCoordinates[0],
|
||||
flatCoordinates[1]
|
||||
);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
const stride = this.stride;
|
||||
for (let i = 0; i < stride; ++i) {
|
||||
@@ -104,10 +108,13 @@ class Point extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinate(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Point;
|
||||
|
||||
+132
-52
@@ -1,24 +1,24 @@
|
||||
/**
|
||||
* @module ol/geom/Polygon
|
||||
*/
|
||||
import {extend} from '../array.js';
|
||||
import {closestSquaredDistanceXY, getCenter} from '../extent.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import GeometryType from './GeometryType.js';
|
||||
import LinearRing from './LinearRing.js';
|
||||
import Point from './Point.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {offset as sphereOffset} from '../sphere.js';
|
||||
import {linearRings as linearRingsArea} from './flat/area.js';
|
||||
import {assignClosestArrayPoint, arrayMaxSquaredDelta} from './flat/closest.js';
|
||||
import {linearRingsContainsXY} from './flat/contains.js';
|
||||
import {arrayMaxSquaredDelta, assignClosestArrayPoint} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY, getCenter} from '../extent.js';
|
||||
import {deflateCoordinatesArray} from './flat/deflate.js';
|
||||
import {inflateCoordinatesArray} from './flat/inflate.js';
|
||||
import {extend} from '../array.js';
|
||||
import {getInteriorPointOfArray} from './flat/interiorpoint.js';
|
||||
import {inflateCoordinatesArray} from './flat/inflate.js';
|
||||
import {intersectsLinearRingArray} from './flat/intersectsextent.js';
|
||||
import {linearRingsAreOriented, orientLinearRings} from './flat/orient.js';
|
||||
import {quantizeArray} from './flat/simplify.js';
|
||||
import {linearRings as linearRingsArea} from './flat/area.js';
|
||||
import {linearRingsContainsXY} from './flat/contains.js';
|
||||
import {modulo} from '../math.js';
|
||||
import {quantizeArray} from './flat/simplify.js';
|
||||
import {offset as sphereOffset} from '../sphere.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -27,7 +27,6 @@ import {modulo} from '../math.js';
|
||||
* @api
|
||||
*/
|
||||
class Polygon extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {!Array<Array<import("../coordinate.js").Coordinate>>|!Array<number>} coordinates
|
||||
* Array of linear rings that define the polygon. The first linear ring of the
|
||||
@@ -40,7 +39,6 @@ class Polygon extends SimpleGeometry {
|
||||
* @param {Array<number>=} opt_ends Ends (for internal use with flat coordinates).
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -86,12 +84,17 @@ class Polygon extends SimpleGeometry {
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
|
||||
if (opt_layout !== undefined && opt_ends) {
|
||||
this.setFlatCoordinates(opt_layout, /** @type {Array<number>} */ (coordinates));
|
||||
this.setFlatCoordinates(
|
||||
opt_layout,
|
||||
/** @type {Array<number>} */ (coordinates)
|
||||
);
|
||||
this.ends_ = opt_ends;
|
||||
} else {
|
||||
this.setCoordinates(/** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ (coordinates), opt_layout);
|
||||
this.setCoordinates(
|
||||
/** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ (coordinates),
|
||||
opt_layout
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +118,11 @@ class Polygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Polygon(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
|
||||
return new Polygon(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
this.ends_.slice()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,13 +137,29 @@ class Polygon extends SimpleGeometry {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDelta_ = Math.sqrt(
|
||||
arrayMaxSquaredDelta(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
0
|
||||
)
|
||||
);
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestArrayPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
this.maxDelta_,
|
||||
true,
|
||||
x,
|
||||
y,
|
||||
closestPoint,
|
||||
minSquaredDistance
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +168,14 @@ class Polygon extends SimpleGeometry {
|
||||
* @return {boolean} Contains (x, y).
|
||||
*/
|
||||
containsXY(x, y) {
|
||||
return linearRingsContainsXY(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
|
||||
return linearRingsContainsXY(
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +184,12 @@ class Polygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getArea() {
|
||||
return linearRingsArea(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
|
||||
return linearRingsArea(
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,14 +209,12 @@ class Polygon extends SimpleGeometry {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
orientLinearRings(
|
||||
flatCoordinates, 0, this.ends_, this.stride, opt_right);
|
||||
orientLinearRings(flatCoordinates, 0, this.ends_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
}
|
||||
|
||||
return inflateCoordinatesArray(
|
||||
flatCoordinates, 0, this.ends_, this.stride);
|
||||
return inflateCoordinatesArray(flatCoordinates, 0, this.ends_, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +231,13 @@ class Polygon extends SimpleGeometry {
|
||||
if (this.flatInteriorPointRevision_ != this.getRevision()) {
|
||||
const flatCenter = getCenter(this.getExtent());
|
||||
this.flatInteriorPoint_ = getInteriorPointOfArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride,
|
||||
flatCenter, 0);
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
flatCenter,
|
||||
0
|
||||
);
|
||||
this.flatInteriorPointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatInteriorPoint_;
|
||||
@@ -240,8 +278,13 @@ class Polygon extends SimpleGeometry {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
return new LinearRing(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
return new LinearRing(
|
||||
this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1],
|
||||
this.ends_[index]
|
||||
),
|
||||
this.layout
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +300,10 @@ class Polygon extends SimpleGeometry {
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const linearRing = new LinearRing(flatCoordinates.slice(offset, end), layout);
|
||||
const linearRing = new LinearRing(
|
||||
flatCoordinates.slice(offset, end),
|
||||
layout
|
||||
);
|
||||
linearRings.push(linearRing);
|
||||
offset = end;
|
||||
}
|
||||
@@ -270,14 +316,16 @@ class Polygon extends SimpleGeometry {
|
||||
getOrientedFlatCoordinates() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (linearRingsAreOriented(
|
||||
flatCoordinates, 0, this.ends_, this.stride)) {
|
||||
if (linearRingsAreOriented(flatCoordinates, 0, this.ends_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
orientLinearRings(
|
||||
this.orientedFlatCoordinates_, 0, this.ends_, this.stride);
|
||||
this.orientedFlatCoordinates_.length = orientLinearRings(
|
||||
this.orientedFlatCoordinates_,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride
|
||||
);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
@@ -293,10 +341,20 @@ class Polygon extends SimpleGeometry {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedFlatCoordinates.length = quantizeArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
Math.sqrt(squaredTolerance),
|
||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||
return new Polygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
|
||||
simplifiedFlatCoordinates,
|
||||
0,
|
||||
simplifiedEnds
|
||||
);
|
||||
return new Polygon(
|
||||
simplifiedFlatCoordinates,
|
||||
GeometryLayout.XY,
|
||||
simplifiedEnds
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +374,12 @@ class Polygon extends SimpleGeometry {
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLinearRingArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, extent);
|
||||
this.getOrientedFlatCoordinates(),
|
||||
0,
|
||||
this.ends_,
|
||||
this.stride,
|
||||
extent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,16 +394,19 @@ class Polygon extends SimpleGeometry {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const ends = deflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
coordinates,
|
||||
this.stride,
|
||||
this.ends_
|
||||
);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Polygon;
|
||||
|
||||
|
||||
/**
|
||||
* Create an approximation of a circle on the surface of a sphere.
|
||||
* @param {import("../coordinate.js").Coordinate} center Center (`[lon, lat]` in degrees).
|
||||
@@ -358,13 +424,17 @@ export function circular(center, radius, opt_n, opt_sphereRadius) {
|
||||
/** @type {Array<number>} */
|
||||
const flatCoordinates = [];
|
||||
for (let i = 0; i < n; ++i) {
|
||||
extend(flatCoordinates, sphereOffset(center, radius, 2 * Math.PI * i / n, opt_sphereRadius));
|
||||
extend(
|
||||
flatCoordinates,
|
||||
sphereOffset(center, radius, (2 * Math.PI * i) / n, opt_sphereRadius)
|
||||
);
|
||||
}
|
||||
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a polygon from an extent. The layout used is `XY`.
|
||||
* @param {import("../extent.js").Extent} extent The extent.
|
||||
@@ -376,12 +446,23 @@ export function fromExtent(extent) {
|
||||
const minY = extent[1];
|
||||
const maxX = extent[2];
|
||||
const maxY = extent[3];
|
||||
const flatCoordinates =
|
||||
[minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY];
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
|
||||
const flatCoordinates = [
|
||||
minX,
|
||||
minY,
|
||||
minX,
|
||||
maxY,
|
||||
maxX,
|
||||
maxY,
|
||||
maxX,
|
||||
minY,
|
||||
minX,
|
||||
minY,
|
||||
];
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a regular polygon from a circle.
|
||||
* @param {import("./Circle.js").default} circle Circle geometry.
|
||||
@@ -411,7 +492,6 @@ export function fromCircle(circle, opt_sides, opt_angle) {
|
||||
return polygon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modify the coordinates of a polygon to make it a regular polygon.
|
||||
* @param {Polygon} polygon Polygon geometry.
|
||||
@@ -427,9 +507,9 @@ export function makeRegular(polygon, center, radius, opt_angle) {
|
||||
const startAngle = opt_angle ? opt_angle : 0;
|
||||
for (let i = 0; i <= sides; ++i) {
|
||||
const offset = i * stride;
|
||||
const angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides);
|
||||
flatCoordinates[offset] = center[0] + (radius * Math.cos(angle));
|
||||
flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle));
|
||||
const angle = startAngle + (modulo(i, sides) * 2 * Math.PI) / sides;
|
||||
flatCoordinates[offset] = center[0] + radius * Math.cos(angle);
|
||||
flatCoordinates[offset + 1] = center[1] + radius * Math.sin(angle);
|
||||
}
|
||||
polygon.changed();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @module ol/geom/SimpleGeometry
|
||||
*/
|
||||
import {abstract} from '../util.js';
|
||||
import {createOrUpdateFromFlatCoordinates, getCenter} from '../extent.js';
|
||||
import Geometry from './Geometry.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import {rotate, scale, translate, transform2D} from './flat/transform.js';
|
||||
import {abstract} from '../util.js';
|
||||
import {createOrUpdateFromFlatCoordinates, getCenter} from '../extent.js';
|
||||
import {rotate, scale, transform2D, translate} from './flat/transform.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -17,7 +17,6 @@ import {rotate, scale, translate, transform2D} from './flat/transform.js';
|
||||
*/
|
||||
class SimpleGeometry extends Geometry {
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
@@ -37,7 +36,6 @@ class SimpleGeometry extends Geometry {
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,8 +44,13 @@ class SimpleGeometry extends Geometry {
|
||||
* @return {import("../extent.js").Extent} extent Extent.
|
||||
*/
|
||||
computeExtent(extent) {
|
||||
return createOrUpdateFromFlatCoordinates(this.flatCoordinates,
|
||||
0, this.flatCoordinates.length, this.stride, extent);
|
||||
return createOrUpdateFromFlatCoordinates(
|
||||
this.flatCoordinates,
|
||||
0,
|
||||
this.flatCoordinates.length,
|
||||
this.stride,
|
||||
extent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +83,9 @@ class SimpleGeometry extends Geometry {
|
||||
* @api
|
||||
*/
|
||||
getLastCoordinate() {
|
||||
return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
|
||||
return this.flatCoordinates.slice(
|
||||
this.flatCoordinates.length - this.stride
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,14 +109,17 @@ class SimpleGeometry extends Geometry {
|
||||
}
|
||||
// If squaredTolerance is negative or if we know that simplification will not
|
||||
// have any effect then just return this.
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
if (
|
||||
squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)
|
||||
) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
const simplifiedGeometry = this.getSimplifiedGeometryInternal(
|
||||
squaredTolerance
|
||||
);
|
||||
const simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
return simplifiedGeometry;
|
||||
@@ -218,8 +226,14 @@ class SimpleGeometry extends Geometry {
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
rotate(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, angle, anchor, flatCoordinates);
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
stride,
|
||||
angle,
|
||||
anchor,
|
||||
flatCoordinates
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
@@ -227,7 +241,7 @@ class SimpleGeometry extends Geometry {
|
||||
/**
|
||||
* Scale the geometry (with an optional origin). This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number=} opt_sy The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate=} opt_anchor The scale origin (defaults to the center
|
||||
* of the geometry extent).
|
||||
@@ -246,8 +260,15 @@ class SimpleGeometry extends Geometry {
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
scale(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, sx, sy, anchor, flatCoordinates);
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
stride,
|
||||
sx,
|
||||
sy,
|
||||
anchor,
|
||||
flatCoordinates
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
@@ -264,14 +285,19 @@ class SimpleGeometry extends Geometry {
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
translate(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||
deltaX, deltaY, flatCoordinates);
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
stride,
|
||||
deltaX,
|
||||
deltaY,
|
||||
flatCoordinates
|
||||
);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} stride Stride.
|
||||
* @return {GeometryLayout} layout Layout.
|
||||
@@ -285,12 +311,9 @@ function getLayoutForStride(stride) {
|
||||
} else if (stride == 4) {
|
||||
layout = GeometryLayout.XYZM;
|
||||
}
|
||||
return (
|
||||
/** @type {GeometryLayout} */ (layout)
|
||||
);
|
||||
return /** @type {GeometryLayout} */ (layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeometryLayout} layout Layout.
|
||||
* @return {number} Stride.
|
||||
@@ -307,7 +330,6 @@ export function getStrideForLayout(layout) {
|
||||
return /** @type {number} */ (stride);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {SimpleGeometry} simpleGeometry Simple geometry.
|
||||
* @param {import("../transform.js").Transform} transform Transform.
|
||||
@@ -321,8 +343,13 @@ export function transformGeom2D(simpleGeometry, transform, opt_dest) {
|
||||
} else {
|
||||
const stride = simpleGeometry.getStride();
|
||||
return transform2D(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||
transform, opt_dest);
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
stride,
|
||||
transform,
|
||||
opt_dest
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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