Replace GeometryLayout enum with typedef
This commit is contained in:
@@ -18,7 +18,7 @@ class Circle extends SimpleGeometry {
|
||||
* For internal use, flat coordinates in combination with `opt_layout` and no
|
||||
* `opt_radius` are also accepted.
|
||||
* @param {number} [opt_radius] Radius.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(center, opt_radius, opt_layout) {
|
||||
super();
|
||||
@@ -188,7 +188,7 @@ class Circle extends SimpleGeometry {
|
||||
* number) of the circle.
|
||||
* @param {!import("../coordinate.js").Coordinate} center Center.
|
||||
* @param {number} radius Radius.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCenterAndRadius(center, radius, opt_layout) {
|
||||
|
||||
@@ -18,6 +18,12 @@ import {get as getProjection, getTransform} from '../proj.js';
|
||||
import {memoizeOne} from '../functions.js';
|
||||
import {transform2D} from './flat/transform.js';
|
||||
|
||||
/**
|
||||
* @typedef {'XY' | 'XYZ' | 'XYM' | 'XYZM'} GeometryLayout
|
||||
* The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z')
|
||||
* or measure ('M') coordinate is available.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'Circle'} Type
|
||||
* The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`,
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* @module ol/geom/GeometryLayout
|
||||
*/
|
||||
|
||||
/**
|
||||
* The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z')
|
||||
* or measure ('M') coordinate is available. Supported values are `'XY'`,
|
||||
* `'XYZ'`, `'XYM'`, `'XYZM'`.
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
XY: 'XY',
|
||||
XYZ: 'XYZ',
|
||||
XYM: 'XYM',
|
||||
XYZM: 'XYZM',
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/LineString
|
||||
*/
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
@@ -24,7 +23,7 @@ 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 {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -169,10 +168,7 @@ class LineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getCoordinateAtM(m, opt_extrapolate) {
|
||||
if (
|
||||
this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM
|
||||
) {
|
||||
if (this.layout != 'XYM' && this.layout != 'XYZM') {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
@@ -263,7 +259,7 @@ class LineString extends SimpleGeometry {
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
);
|
||||
return new LineString(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
return new LineString(simplifiedFlatCoordinates, 'XY');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +290,7 @@ class LineString extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the linestring.
|
||||
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/LinearRing
|
||||
*/
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js';
|
||||
import {closestSquaredDistanceXY} from '../extent.js';
|
||||
@@ -21,7 +20,7 @@ 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 {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -143,7 +142,7 @@ class LinearRing extends SimpleGeometry {
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
);
|
||||
return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
return new LinearRing(simplifiedFlatCoordinates, 'XY');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +167,7 @@ class LinearRing extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the linear ring.
|
||||
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/MultiLineString
|
||||
*/
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import LineString from './LineString.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
import {arrayMaxSquaredDelta, assignClosestArrayPoint} from './flat/closest.js';
|
||||
@@ -27,7 +26,7 @@ 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
|
||||
* combination with `opt_layout` and `opt_ends` are also accepted.)
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @param {Array<number>} [opt_ends] Flat coordinate ends for internal use.
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
@@ -173,8 +172,7 @@ class MultiLineString extends SimpleGeometry {
|
||||
*/
|
||||
getCoordinateAtM(m, opt_extrapolate, opt_interpolate) {
|
||||
if (
|
||||
(this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) ||
|
||||
(this.layout != 'XYM' && this.layout != 'XYZM') ||
|
||||
this.flatCoordinates.length === 0
|
||||
) {
|
||||
return null;
|
||||
@@ -298,11 +296,7 @@ class MultiLineString extends SimpleGeometry {
|
||||
0,
|
||||
simplifiedEnds
|
||||
);
|
||||
return new MultiLineString(
|
||||
simplifiedFlatCoordinates,
|
||||
GeometryLayout.XY,
|
||||
simplifiedEnds
|
||||
);
|
||||
return new MultiLineString(simplifiedFlatCoordinates, 'XY', simplifiedEnds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +327,7 @@ class MultiLineString extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the multilinestring.
|
||||
* @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates.
|
||||
* @param {GeometryLayout} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -19,7 +19,7 @@ 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.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -182,7 +182,7 @@ class MultiPoint extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the multipoint.
|
||||
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/MultiPolygon
|
||||
*/
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import MultiPoint from './MultiPoint.js';
|
||||
import Polygon from './Polygon.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
@@ -34,7 +33,7 @@ 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.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @param {Array<Array<number>>} [opt_endss] Array of ends for internal use with flat coordinates.
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_endss) {
|
||||
@@ -306,10 +305,7 @@ class MultiPolygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getInteriorPoints() {
|
||||
return new MultiPoint(
|
||||
this.getFlatInteriorPoints().slice(),
|
||||
GeometryLayout.XYM
|
||||
);
|
||||
return new MultiPoint(this.getFlatInteriorPoints().slice(), 'XYM');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,11 +350,7 @@ class MultiPolygon extends SimpleGeometry {
|
||||
0,
|
||||
simplifiedEndss
|
||||
);
|
||||
return new MultiPolygon(
|
||||
simplifiedFlatCoordinates,
|
||||
GeometryLayout.XY,
|
||||
simplifiedEndss
|
||||
);
|
||||
return new MultiPolygon(simplifiedFlatCoordinates, 'XY', simplifiedEndss);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,7 +442,7 @@ class MultiPolygon extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the multipolygon.
|
||||
* @param {!Array<Array<Array<import("../coordinate.js").Coordinate>>>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {squaredDistance as squaredDx} from '../math.js';
|
||||
class Point extends SimpleGeometry {
|
||||
/**
|
||||
* @param {import("../coordinate.js").Coordinate} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -99,7 +99,7 @@ class Point extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {!Array<*>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
+6
-15
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/Polygon
|
||||
*/
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import LinearRing from './LinearRing.js';
|
||||
import Point from './Point.js';
|
||||
import SimpleGeometry from './SimpleGeometry.js';
|
||||
@@ -34,7 +33,7 @@ class Polygon extends SimpleGeometry {
|
||||
* an array of vertices' coordinates where the first coordinate and the last are
|
||||
* equivalent. (For internal use, flat coordinates in combination with
|
||||
* `opt_layout` and `opt_ends` are also accepted.)
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @param {Array<number>} [opt_ends] Ends (for internal use with flat coordinates).
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
@@ -253,7 +252,7 @@ class Polygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
getInteriorPoint() {
|
||||
return new Point(this.getFlatInteriorPoint(), GeometryLayout.XYM);
|
||||
return new Point(this.getFlatInteriorPoint(), 'XYM');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,11 +352,7 @@ class Polygon extends SimpleGeometry {
|
||||
0,
|
||||
simplifiedEnds
|
||||
);
|
||||
return new Polygon(
|
||||
simplifiedFlatCoordinates,
|
||||
GeometryLayout.XY,
|
||||
simplifiedEnds
|
||||
);
|
||||
return new Polygon(simplifiedFlatCoordinates, 'XY', simplifiedEnds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +383,7 @@ class Polygon extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the polygon.
|
||||
* @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
@@ -433,9 +428,7 @@ export function circular(center, radius, opt_n, opt_sphereRadius) {
|
||||
);
|
||||
}
|
||||
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
return new Polygon(flatCoordinates, 'XY', [flatCoordinates.length]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,9 +454,7 @@ export function fromExtent(extent) {
|
||||
minX,
|
||||
minY,
|
||||
];
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
return new Polygon(flatCoordinates, 'XY', [flatCoordinates.length]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/SimpleGeometry
|
||||
*/
|
||||
import Geometry from './Geometry.js';
|
||||
import GeometryLayout from './GeometryLayout.js';
|
||||
import {abstract} from '../util.js';
|
||||
import {createOrUpdateFromFlatCoordinates, getCenter} from '../extent.js';
|
||||
import {rotate, scale, transform2D, translate} from './flat/transform.js';
|
||||
@@ -21,9 +20,9 @@ class SimpleGeometry extends Geometry {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("./GeometryLayout.js").default}
|
||||
* @type {import("./Geometry.js").GeometryLayout}
|
||||
*/
|
||||
this.layout = GeometryLayout.XY;
|
||||
this.layout = 'XY';
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -89,8 +88,8 @@ class SimpleGeometry extends Geometry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/geom/GeometryLayout layout} of the geometry.
|
||||
* @return {import("./GeometryLayout.js").default} Layout.
|
||||
* Return the {@link import("./Geometry.js").GeometryLayout layout} of the geometry.
|
||||
* @return {import("./Geometry.js").GeometryLayout} Layout.
|
||||
* @api
|
||||
*/
|
||||
getLayout() {
|
||||
@@ -151,7 +150,7 @@ class SimpleGeometry extends Geometry {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./GeometryLayout.js").default} layout Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} layout Layout.
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
setFlatCoordinates(layout, flatCoordinates) {
|
||||
@@ -163,14 +162,14 @@ class SimpleGeometry extends Geometry {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {!Array<*>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout.
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./GeometryLayout.js").default|undefined} layout Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array<*>} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
@@ -183,7 +182,7 @@ class SimpleGeometry extends Geometry {
|
||||
} else {
|
||||
for (let i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = GeometryLayout.XY;
|
||||
this.layout = 'XY';
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
@@ -299,31 +298,31 @@ class SimpleGeometry extends Geometry {
|
||||
|
||||
/**
|
||||
* @param {number} stride Stride.
|
||||
* @return {import("./GeometryLayout.js").default} layout Layout.
|
||||
* @return {import("./Geometry.js").GeometryLayout} layout Layout.
|
||||
*/
|
||||
function getLayoutForStride(stride) {
|
||||
let layout;
|
||||
if (stride == 2) {
|
||||
layout = GeometryLayout.XY;
|
||||
layout = 'XY';
|
||||
} else if (stride == 3) {
|
||||
layout = GeometryLayout.XYZ;
|
||||
layout = 'XYZ';
|
||||
} else if (stride == 4) {
|
||||
layout = GeometryLayout.XYZM;
|
||||
layout = 'XYZM';
|
||||
}
|
||||
return /** @type {import("./GeometryLayout.js").default} */ (layout);
|
||||
return /** @type {import("./Geometry.js").GeometryLayout} */ (layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./GeometryLayout.js").default} layout Layout.
|
||||
* @param {import("./Geometry.js").GeometryLayout} layout Layout.
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
export function getStrideForLayout(layout) {
|
||||
let stride;
|
||||
if (layout == GeometryLayout.XY) {
|
||||
if (layout == 'XY') {
|
||||
stride = 2;
|
||||
} else if (layout == GeometryLayout.XYZ || layout == GeometryLayout.XYM) {
|
||||
} else if (layout == 'XYZ' || layout == 'XYM') {
|
||||
stride = 3;
|
||||
} else if (layout == GeometryLayout.XYZM) {
|
||||
} else if (layout == 'XYZM') {
|
||||
stride = 4;
|
||||
}
|
||||
return /** @type {number} */ (stride);
|
||||
|
||||
Reference in New Issue
Block a user