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
+104 -93
View File
@@ -1,10 +1,9 @@
/**
* @module ol/extent
*/
import {assert} from './asserts.js';
import Corner from './extent/Corner.js';
import Relationship from './extent/Relationship.js';
import {assert} from './asserts.js';
/**
* An array of numbers representing an extent: `[minx, miny, maxx, maxy]`.
@@ -27,7 +26,6 @@ export function boundingExtent(coordinates) {
return extent;
}
/**
* @param {Array<number>} xs Xs.
* @param {Array<number>} ys Ys.
@@ -43,7 +41,6 @@ function _boundingExtentXYs(xs, ys, opt_extent) {
return createOrUpdate(minX, minY, maxX, maxY, opt_extent);
}
/**
* Return extent increased by the provided value.
* @param {Extent} extent Extent.
@@ -64,12 +61,11 @@ export function buffer(extent, value, opt_extent) {
extent[0] - value,
extent[1] - value,
extent[2] + value,
extent[3] + value
extent[3] + value,
];
}
}
/**
* Creates a clone of an extent.
*
@@ -89,7 +85,6 @@ export function clone(extent, opt_extent) {
}
}
/**
* @param {Extent} extent Extent.
* @param {number} x X.
@@ -115,7 +110,6 @@ export function closestSquaredDistanceXY(extent, x, y) {
return dx * dx + dy * dy;
}
/**
* Check if the passed coordinate is contained or on the edge of the extent.
*
@@ -128,7 +122,6 @@ export function containsCoordinate(extent, coordinate) {
return containsXY(extent, coordinate[0], coordinate[1]);
}
/**
* Check if one extent contains another.
*
@@ -142,11 +135,14 @@ export function containsCoordinate(extent, coordinate) {
* @api
*/
export function containsExtent(extent1, extent2) {
return extent1[0] <= extent2[0] && extent2[2] <= extent1[2] &&
extent1[1] <= extent2[1] && extent2[3] <= extent1[3];
return (
extent1[0] <= extent2[0] &&
extent2[2] <= extent1[2] &&
extent1[1] <= extent2[1] &&
extent2[3] <= extent1[3]
);
}
/**
* Check if the passed coordinate is contained or on the edge of the extent.
*
@@ -160,7 +156,6 @@ export function containsXY(extent, x, y) {
return extent[0] <= x && x <= extent[2] && extent[1] <= y && y <= extent[3];
}
/**
* Get the relationship between a coordinate and extent.
* @param {Extent} extent The extent.
@@ -192,7 +187,6 @@ export function coordinateRelationship(extent, coordinate) {
return relationship;
}
/**
* Create an empty extent.
* @return {Extent} Empty extent.
@@ -202,7 +196,6 @@ export function createEmpty() {
return [Infinity, Infinity, -Infinity, -Infinity];
}
/**
* Create a new extent or update the provided extent.
* @param {number} minX Minimum X.
@@ -224,18 +217,15 @@ export function createOrUpdate(minX, minY, maxX, maxY, opt_extent) {
}
}
/**
* Create a new empty extent or make the provided one empty.
* @param {Extent=} opt_extent Extent.
* @return {Extent} Extent.
*/
export function createOrUpdateEmpty(opt_extent) {
return createOrUpdate(
Infinity, Infinity, -Infinity, -Infinity, opt_extent);
return createOrUpdate(Infinity, Infinity, -Infinity, -Infinity, opt_extent);
}
/**
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
* @param {Extent=} opt_extent Extent.
@@ -247,7 +237,6 @@ export function createOrUpdateFromCoordinate(coordinate, opt_extent) {
return createOrUpdate(x, y, x, y, opt_extent);
}
/**
* @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates.
* @param {Extent=} opt_extent Extent.
@@ -258,7 +247,6 @@ export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
return extendCoordinates(extent, coordinates);
}
/**
* @param {Array<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
@@ -267,7 +255,13 @@ export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
* @param {Extent=} opt_extent Extent.
* @return {Extent} Extent.
*/
export function createOrUpdateFromFlatCoordinates(flatCoordinates, offset, end, stride, opt_extent) {
export function createOrUpdateFromFlatCoordinates(
flatCoordinates,
offset,
end,
stride,
opt_extent
) {
const extent = createOrUpdateEmpty(opt_extent);
return extendFlatCoordinates(extent, flatCoordinates, offset, end, stride);
}
@@ -282,7 +276,6 @@ export function createOrUpdateFromRings(rings, opt_extent) {
return extendRings(extent, rings);
}
/**
* Determine if two extents are equivalent.
* @param {Extent} extent1 Extent 1.
@@ -291,8 +284,12 @@ export function createOrUpdateFromRings(rings, opt_extent) {
* @api
*/
export function equals(extent1, extent2) {
return extent1[0] == extent2[0] && extent1[2] == extent2[2] &&
extent1[1] == extent2[1] && extent1[3] == extent2[3];
return (
extent1[0] == extent2[0] &&
extent1[2] == extent2[2] &&
extent1[1] == extent2[1] &&
extent1[3] == extent2[3]
);
}
/**
@@ -303,11 +300,14 @@ export function equals(extent1, extent2) {
* @return {boolean} The two extents differ by less than the tolerance.
*/
export function approximatelyEquals(extent1, extent2, tolerance) {
return Math.abs(extent1[0] - extent2[0]) < tolerance && Math.abs(extent1[2] - extent2[2]) < tolerance &&
Math.abs(extent1[1] - extent2[1]) < tolerance && Math.abs(extent1[3] - extent2[3]) < tolerance;
return (
Math.abs(extent1[0] - extent2[0]) < tolerance &&
Math.abs(extent1[2] - extent2[2]) < tolerance &&
Math.abs(extent1[1] - extent2[1]) < tolerance &&
Math.abs(extent1[3] - extent2[3]) < tolerance
);
}
/**
* Modify an extent to include another extent.
* @param {Extent} extent1 The extent to be modified.
@@ -331,7 +331,6 @@ export function extend(extent1, extent2) {
return extent1;
}
/**
* @param {Extent} extent Extent.
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
@@ -351,7 +350,6 @@ export function extendCoordinate(extent, coordinate) {
}
}
/**
* @param {Extent} extent Extent.
* @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates.
@@ -364,7 +362,6 @@ export function extendCoordinates(extent, coordinates) {
return extent;
}
/**
* @param {Extent} extent Extent.
* @param {Array<number>} flatCoordinates Flat coordinates.
@@ -373,14 +370,19 @@ export function extendCoordinates(extent, coordinates) {
* @param {number} stride Stride.
* @return {Extent} Extent.
*/
export function extendFlatCoordinates(extent, flatCoordinates, offset, end, stride) {
export function extendFlatCoordinates(
extent,
flatCoordinates,
offset,
end,
stride
) {
for (; offset < end; offset += stride) {
extendXY(extent, flatCoordinates[offset], flatCoordinates[offset + 1]);
}
return extent;
}
/**
* @param {Extent} extent Extent.
* @param {Array<Array<import("./coordinate.js").Coordinate>>} rings Rings.
@@ -393,7 +395,6 @@ export function extendRings(extent, rings) {
return extent;
}
/**
* @param {Extent} extent Extent.
* @param {number} x X.
@@ -406,7 +407,6 @@ export function extendXY(extent, x, y) {
extent[3] = Math.max(extent[3], y);
}
/**
* This function calls `callback` for each corner of the extent. If the
* callback returns a truthy value the function returns that value
@@ -437,7 +437,6 @@ export function forEachCorner(extent, callback) {
return false;
}
/**
* Get the size of an extent.
* @param {Extent} extent Extent.
@@ -452,7 +451,6 @@ export function getArea(extent) {
return area;
}
/**
* Get the bottom left coordinate of an extent.
* @param {Extent} extent Extent.
@@ -463,7 +461,6 @@ export function getBottomLeft(extent) {
return [extent[0], extent[1]];
}
/**
* Get the bottom right coordinate of an extent.
* @param {Extent} extent Extent.
@@ -474,7 +471,6 @@ export function getBottomRight(extent) {
return [extent[2], extent[1]];
}
/**
* Get the center coordinate of an extent.
* @param {Extent} extent Extent.
@@ -485,7 +481,6 @@ export function getCenter(extent) {
return [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
}
/**
* Get a corner coordinate of an extent.
* @param {Extent} extent Extent.
@@ -508,7 +503,6 @@ export function getCorner(extent, corner) {
return coordinate;
}
/**
* @param {Extent} extent1 Extent 1.
* @param {Extent} extent2 Extent 2.
@@ -522,7 +516,6 @@ export function getEnlargedArea(extent1, extent2) {
return (maxX - minX) * (maxY - minY);
}
/**
* @param {import("./coordinate.js").Coordinate} center Center.
* @param {number} resolution Resolution.
@@ -531,9 +524,15 @@ export function getEnlargedArea(extent1, extent2) {
* @param {Extent=} opt_extent Destination extent.
* @return {Extent} Extent.
*/
export function getForViewAndSize(center, resolution, rotation, size, opt_extent) {
const dx = resolution * size[0] / 2;
const dy = resolution * size[1] / 2;
export function getForViewAndSize(
center,
resolution,
rotation,
size,
opt_extent
) {
const dx = (resolution * size[0]) / 2;
const dy = (resolution * size[1]) / 2;
const cosRotation = Math.cos(rotation);
const sinRotation = Math.sin(rotation);
const xCos = dx * cosRotation;
@@ -551,12 +550,14 @@ export function getForViewAndSize(center, resolution, rotation, size, opt_extent
const y2 = y + xSin + yCos;
const y3 = y + xSin - yCos;
return createOrUpdate(
Math.min(x0, x1, x2, x3), Math.min(y0, y1, y2, y3),
Math.max(x0, x1, x2, x3), Math.max(y0, y1, y2, y3),
opt_extent);
Math.min(x0, x1, x2, x3),
Math.min(y0, y1, y2, y3),
Math.max(x0, x1, x2, x3),
Math.max(y0, y1, y2, y3),
opt_extent
);
}
/**
* Get the height of an extent.
* @param {Extent} extent Extent.
@@ -567,7 +568,6 @@ export function getHeight(extent) {
return extent[3] - extent[1];
}
/**
* @param {Extent} extent1 Extent 1.
* @param {Extent} extent2 Extent 2.
@@ -578,7 +578,6 @@ export function getIntersectionArea(extent1, extent2) {
return getArea(intersection);
}
/**
* Get the intersection of two extents.
* @param {Extent} extent1 Extent 1.
@@ -616,7 +615,6 @@ export function getIntersection(extent1, extent2, opt_extent) {
return intersection;
}
/**
* @param {Extent} extent Extent.
* @return {number} Margin.
@@ -625,7 +623,6 @@ export function getMargin(extent) {
return getWidth(extent) + getHeight(extent);
}
/**
* Get the size (width, height) of an extent.
* @param {Extent} extent The extent.
@@ -636,7 +633,6 @@ export function getSize(extent) {
return [extent[2] - extent[0], extent[3] - extent[1]];
}
/**
* Get the top left coordinate of an extent.
* @param {Extent} extent Extent.
@@ -647,7 +643,6 @@ export function getTopLeft(extent) {
return [extent[0], extent[3]];
}
/**
* Get the top right coordinate of an extent.
* @param {Extent} extent Extent.
@@ -658,7 +653,6 @@ export function getTopRight(extent) {
return [extent[2], extent[3]];
}
/**
* Get the width of an extent.
* @param {Extent} extent Extent.
@@ -669,7 +663,6 @@ export function getWidth(extent) {
return extent[2] - extent[0];
}
/**
* Determine if one extent intersects another.
* @param {Extent} extent1 Extent 1.
@@ -678,13 +671,14 @@ export function getWidth(extent) {
* @api
*/
export function intersects(extent1, extent2) {
return extent1[0] <= extent2[2] &&
extent1[2] >= extent2[0] &&
extent1[1] <= extent2[3] &&
extent1[3] >= extent2[1];
return (
extent1[0] <= extent2[2] &&
extent1[2] >= extent2[0] &&
extent1[1] <= extent2[3] &&
extent1[3] >= extent2[1]
);
}
/**
* Determine if an extent is empty.
* @param {Extent} extent Extent.
@@ -695,7 +689,6 @@ export function isEmpty(extent) {
return extent[2] < extent[0] || extent[3] < extent[1];
}
/**
* @param {Extent} extent Extent.
* @param {Extent=} opt_extent Extent.
@@ -713,7 +706,6 @@ export function returnOrUpdate(extent, opt_extent) {
}
}
/**
* @param {Extent} extent Extent.
* @param {number} value Value.
@@ -727,7 +719,6 @@ export function scaleFromCenter(extent, value) {
extent[3] += deltaY;
}
/**
* Determine if the segment between two coordinates intersects (crosses,
* touches, or is contained by) the provided extent.
@@ -740,8 +731,10 @@ export function intersectsSegment(extent, start, end) {
let intersects = false;
const startRel = coordinateRelationship(extent, start);
const endRel = coordinateRelationship(extent, end);
if (startRel === Relationship.INTERSECTING ||
endRel === Relationship.INTERSECTING) {
if (
startRel === Relationship.INTERSECTING ||
endRel === Relationship.INTERSECTING
) {
intersects = true;
} else {
const minX = extent[0];
@@ -754,36 +747,42 @@ export function intersectsSegment(extent, start, end) {
const endY = end[1];
const slope = (endY - startY) / (endX - startX);
let x, y;
if (!!(endRel & Relationship.ABOVE) &&
!(startRel & Relationship.ABOVE)) {
if (!!(endRel & Relationship.ABOVE) && !(startRel & Relationship.ABOVE)) {
// potentially intersects top
x = endX - ((endY - maxY) / slope);
x = endX - (endY - maxY) / slope;
intersects = x >= minX && x <= maxX;
}
if (!intersects && !!(endRel & Relationship.RIGHT) &&
!(startRel & Relationship.RIGHT)) {
if (
!intersects &&
!!(endRel & Relationship.RIGHT) &&
!(startRel & Relationship.RIGHT)
) {
// potentially intersects right
y = endY - ((endX - maxX) * slope);
y = endY - (endX - maxX) * slope;
intersects = y >= minY && y <= maxY;
}
if (!intersects && !!(endRel & Relationship.BELOW) &&
!(startRel & Relationship.BELOW)) {
if (
!intersects &&
!!(endRel & Relationship.BELOW) &&
!(startRel & Relationship.BELOW)
) {
// potentially intersects bottom
x = endX - ((endY - minY) / slope);
x = endX - (endY - minY) / slope;
intersects = x >= minX && x <= maxX;
}
if (!intersects && !!(endRel & Relationship.LEFT) &&
!(startRel & Relationship.LEFT)) {
if (
!intersects &&
!!(endRel & Relationship.LEFT) &&
!(startRel & Relationship.LEFT)
) {
// potentially intersects left
y = endY - ((endX - minX) * slope);
y = endY - (endX - minX) * slope;
intersects = y >= minY && y <= maxY;
}
}
return intersects;
}
/**
* Apply a transform function to the extent.
* @param {Extent} extent Extent.
@@ -802,18 +801,26 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
const height = extent[3] - extent[1];
for (let i = 0; i < opt_stops; ++i) {
coordinates.push(
extent[0] + width * i / opt_stops, extent[1],
extent[2], extent[1] + height * i / opt_stops,
extent[2] - width * i / opt_stops, extent[3],
extent[0], extent[3] - height * i / opt_stops
extent[0] + (width * i) / opt_stops,
extent[1],
extent[2],
extent[1] + (height * i) / opt_stops,
extent[2] - (width * i) / opt_stops,
extent[3],
extent[0],
extent[3] - (height * i) / opt_stops
);
}
} else {
coordinates = [
extent[0], extent[1],
extent[2], extent[1],
extent[2], extent[3],
extent[0], extent[3]
extent[0],
extent[1],
extent[2],
extent[1],
extent[2],
extent[3],
extent[0],
extent[3],
];
}
transformFn(coordinates, coordinates, 2);
@@ -826,7 +833,6 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
return _boundingExtentXYs(xs, ys, opt_extent);
}
/**
* Modifies the provided extent in-place to be within the real world
* extent.
@@ -838,10 +844,15 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
export function wrapX(extent, projection) {
const projectionExtent = projection.getExtent();
const center = getCenter(extent);
if (projection.canWrapX() && (center[0] < projectionExtent[0] || center[0] >= projectionExtent[2])) {
if (
projection.canWrapX() &&
(center[0] < projectionExtent[0] || center[0] >= projectionExtent[2])
) {
const worldWidth = getWidth(projectionExtent);
const worldsAway = Math.floor((center[0] - projectionExtent[0]) / worldWidth);
const offset = (worldsAway * worldWidth);
const worldsAway = Math.floor(
(center[0] - projectionExtent[0]) / worldWidth
);
const offset = worldsAway * worldWidth;
extent[0] -= offset;
extent[2] -= offset;
}