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:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions
+132 -52
View File
@@ -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();
}