Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
@@ -19,29 +19,243 @@ import {clear} from '../obj.js';
|
||||
* @extends {module:ol/geom/Geometry}
|
||||
* @api
|
||||
*/
|
||||
const SimpleGeometry = function() {
|
||||
class SimpleGeometry {
|
||||
constructor() {
|
||||
|
||||
Geometry.call(this);
|
||||
Geometry.call(this);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/geom/GeometryLayout}
|
||||
*/
|
||||
this.layout = GeometryLayout.XY;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.stride = 2;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/geom/GeometryLayout}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.layout = GeometryLayout.XY;
|
||||
computeExtent(extent) {
|
||||
return createOrUpdateFromFlatCoordinates(this.flatCoordinates,
|
||||
0, this.flatCoordinates.length, this.stride, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
* @abstract
|
||||
* @return {Array} Coordinates.
|
||||
*/
|
||||
this.stride = 2;
|
||||
getCoordinates() {}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
* Return the first coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} First coordinate.
|
||||
* @api
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
getFirstCoordinate() {
|
||||
return this.flatCoordinates.slice(0, this.stride);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
getFlatCoordinates() {
|
||||
return this.flatCoordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} Last point.
|
||||
* @api
|
||||
*/
|
||||
getLastCoordinate() {
|
||||
return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/geom/GeometryLayout~GeometryLayout layout} of the geometry.
|
||||
* @return {module:ol/geom/GeometryLayout} Layout.
|
||||
* @api
|
||||
*/
|
||||
getLayout() {
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometry(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
// 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)) {
|
||||
return this;
|
||||
}
|
||||
const key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
const simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
const simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometry;
|
||||
return simplifiedGeometry;
|
||||
} else {
|
||||
// Simplification did not actually remove any coordinates. We now know
|
||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||
// than or equal to the current squaredTolerance will also not have any
|
||||
// effect. This allows us to short circuit simplification (saving CPU
|
||||
// cycles) and prevents the cache of simplified geometries from filling
|
||||
// up with useless identical copies of this geometry (saving memory).
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {module:ol/geom/SimpleGeometry} Simplified geometry.
|
||||
* @protected
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
getStride() {
|
||||
return this.stride;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
setFlatCoordinates(layout, flatCoordinates) {
|
||||
this.stride = getStrideForLayout(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {!Array} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {}
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
*/
|
||||
setLayout(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
let stride;
|
||||
if (layout) {
|
||||
stride = getStrideForLayout(layout);
|
||||
} else {
|
||||
for (let i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = GeometryLayout.XY;
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||
}
|
||||
}
|
||||
stride = coordinates.length;
|
||||
layout = getLayoutForStride(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
applyTransform(transformFn) {
|
||||
if (this.flatCoordinates) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
rotate(angle, anchor) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
rotate(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, angle, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
scale(sx, opt_sy, opt_anchor) {
|
||||
let sy = opt_sy;
|
||||
if (sy === undefined) {
|
||||
sy = sx;
|
||||
}
|
||||
let anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = getCenter(this.getExtent());
|
||||
}
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
scale(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, sx, sy, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
translate(deltaX, deltaY) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
translate(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||
deltaX, deltaY, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inherits(SimpleGeometry, Geometry);
|
||||
|
||||
@@ -88,234 +302,6 @@ export function getStrideForLayout(layout) {
|
||||
SimpleGeometry.prototype.containsXY = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
SimpleGeometry.prototype.computeExtent = function(extent) {
|
||||
return createOrUpdateFromFlatCoordinates(this.flatCoordinates,
|
||||
0, this.flatCoordinates.length, this.stride, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {Array} Coordinates.
|
||||
*/
|
||||
SimpleGeometry.prototype.getCoordinates = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Return the first coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} First coordinate.
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.getFirstCoordinate = function() {
|
||||
return this.flatCoordinates.slice(0, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
SimpleGeometry.prototype.getFlatCoordinates = function() {
|
||||
return this.flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the last coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} Last point.
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.getLastCoordinate = function() {
|
||||
return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/geom/GeometryLayout~GeometryLayout layout} of the geometry.
|
||||
* @return {module:ol/geom/GeometryLayout} Layout.
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.getLayout = function() {
|
||||
return this.layout;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
SimpleGeometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
// 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)) {
|
||||
return this;
|
||||
}
|
||||
const key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
const simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
const simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometry;
|
||||
return simplifiedGeometry;
|
||||
} else {
|
||||
// Simplification did not actually remove any coordinates. We now know
|
||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||
// than or equal to the current squaredTolerance will also not have any
|
||||
// effect. This allows us to short circuit simplification (saving CPU
|
||||
// cycles) and prevents the cache of simplified geometries from filling
|
||||
// up with useless identical copies of this geometry (saving memory).
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {module:ol/geom/SimpleGeometry} Simplified geometry.
|
||||
* @protected
|
||||
*/
|
||||
SimpleGeometry.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
SimpleGeometry.prototype.getStride = function() {
|
||||
return this.stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
SimpleGeometry.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
|
||||
this.stride = getStrideForLayout(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {!Array} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
*/
|
||||
SimpleGeometry.prototype.setLayout = function(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
let stride;
|
||||
if (layout) {
|
||||
stride = getStrideForLayout(layout);
|
||||
} else {
|
||||
for (let i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = GeometryLayout.XY;
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||
}
|
||||
}
|
||||
stride = coordinates.length;
|
||||
layout = getLayoutForStride(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.applyTransform = function(transformFn) {
|
||||
if (this.flatCoordinates) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.rotate = function(angle, anchor) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
rotate(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, angle, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.scale = function(sx, opt_sy, opt_anchor) {
|
||||
let sy = opt_sy;
|
||||
if (sy === undefined) {
|
||||
sy = sx;
|
||||
}
|
||||
let anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = getCenter(this.getExtent());
|
||||
}
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
scale(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, sx, sy, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.translate = function(deltaX, deltaY) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
translate(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||
deltaX, deltaY, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/SimpleGeometry} simpleGeometry Simple geometry.
|
||||
* @param {module:ol/transform~Transform} transform Transform.
|
||||
|
||||
Reference in New Issue
Block a user