Merge pull request #7745 from fredj/named

More named exports
This commit is contained in:
Frédéric Junod
2018-01-27 07:04:18 +01:00
committed by GitHub
28 changed files with 161 additions and 225 deletions
+5 -7
View File
@@ -6,7 +6,7 @@ import {intersects, getCenter} from './extent.js';
import GeometryLayout from './geom/GeometryLayout.js'; import GeometryLayout from './geom/GeometryLayout.js';
import LineString from './geom/LineString.js'; import LineString from './geom/LineString.js';
import Point from './geom/Point.js'; import Point from './geom/Point.js';
import _ol_geom_flat_geodesic_ from './geom/flat/geodesic.js'; import {meridian, parallel} from './geom/flat/geodesic.js';
import {clamp} from './math.js'; import {clamp} from './math.js';
import {get as getProjection, equivalent as equivalentProjection, getTransform, transformExtent} from './proj.js'; import {get as getProjection, equivalent as equivalentProjection, getTransform, transformExtent} from './proj.js';
import RenderEventType from './render/EventType.js'; import RenderEventType from './render/EventType.js';
@@ -565,9 +565,8 @@ Graticule.prototype.getMap = function() {
* @param {number} index Index. * @param {number} index Index.
* @private * @private
*/ */
Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat, Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat, squaredTolerance, index) {
squaredTolerance, index) { const flatCoordinates = meridian(lon,
const flatCoordinates = _ol_geom_flat_geodesic_.meridian(lon,
minLat, maxLat, this.projection_, squaredTolerance); minLat, maxLat, this.projection_, squaredTolerance);
const lineString = this.meridians_[index] !== undefined ? const lineString = this.meridians_[index] !== undefined ?
this.meridians_[index] : new LineString(null); this.meridians_[index] : new LineString(null);
@@ -595,9 +594,8 @@ Graticule.prototype.getMeridians = function() {
* @param {number} index Index. * @param {number} index Index.
* @private * @private
*/ */
Graticule.prototype.getParallel_ = function(lat, minLon, maxLon, Graticule.prototype.getParallel_ = function(lat, minLon, maxLon, squaredTolerance, index) {
squaredTolerance, index) { const flatCoordinates = parallel(lat,
const flatCoordinates = _ol_geom_flat_geodesic_.parallel(lat,
minLon, maxLon, this.projection_, squaredTolerance); minLon, maxLon, this.projection_, squaredTolerance);
const lineString = this.parallels_[index] !== undefined ? const lineString = this.parallels_[index] !== undefined ?
this.parallels_[index] : new LineString(null); this.parallels_[index] : new LineString(null);
+3 -5
View File
@@ -9,7 +9,7 @@ import TextFeature from '../format/TextFeature.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
import {getStrideForLayout} from '../geom/SimpleGeometry.js'; import {getStrideForLayout} from '../geom/SimpleGeometry.js';
import _ol_geom_flat_flip_ from '../geom/flat/flip.js'; import {flipXY} from '../geom/flat/flip.js';
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
@@ -326,8 +326,7 @@ Polyline.prototype.readGeometry;
Polyline.prototype.readGeometryFromText = function(text, opt_options) { Polyline.prototype.readGeometryFromText = function(text, opt_options) {
const stride = getStrideForLayout(this.geometryLayout_); const stride = getStrideForLayout(this.geometryLayout_);
const flatCoordinates = decodeDeltas(text, stride, this.factor_); const flatCoordinates = decodeDeltas(text, stride, this.factor_);
_ol_geom_flat_flip_.flipXY( flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
const coordinates = _ol_geom_flat_inflate_.coordinates( const coordinates = _ol_geom_flat_inflate_.coordinates(
flatCoordinates, 0, flatCoordinates.length, stride); flatCoordinates, 0, flatCoordinates.length, stride);
@@ -392,8 +391,7 @@ Polyline.prototype.writeGeometryText = function(geometry, opt_options) {
(transformWithOptions(geometry, true, this.adaptOptions(opt_options))); (transformWithOptions(geometry, true, this.adaptOptions(opt_options)));
const flatCoordinates = geometry.getFlatCoordinates(); const flatCoordinates = geometry.getFlatCoordinates();
const stride = geometry.getStride(); const stride = geometry.getStride();
_ol_geom_flat_flip_.flipXY( flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
return encodeDeltas(flatCoordinates, stride, this.factor_); return encodeDeltas(flatCoordinates, stride, this.factor_);
}; };
export default Polyline; export default Polyline;
+2 -3
View File
@@ -13,7 +13,7 @@ import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
import _ol_geom_flat_length_ from '../geom/flat/length.js'; import _ol_geom_flat_length_ from '../geom/flat/length.js';
import _ol_geom_flat_segments_ from '../geom/flat/segments.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js';
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
/** /**
@@ -119,8 +119,7 @@ LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis
* @api * @api
*/ */
LineString.prototype.forEachSegment = function(callback) { LineString.prototype.forEachSegment = function(callback) {
return _ol_geom_flat_segments_.forEach(this.flatCoordinates, 0, return forEachSegment(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, callback);
this.flatCoordinates.length, this.stride, callback);
}; };
+2 -3
View File
@@ -6,7 +6,7 @@ import {closestSquaredDistanceXY} from '../extent.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
import _ol_geom_flat_area_ from '../geom/flat/area.js'; import {linearRing as linearRingArea} from '../geom/flat/area.js';
import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js';
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
@@ -83,8 +83,7 @@ LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis
* @api * @api
*/ */
LinearRing.prototype.getArea = function() { LinearRing.prototype.getArea = function() {
return _ol_geom_flat_area_.linearRing( return linearRingArea(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
}; };
+6 -8
View File
@@ -9,10 +9,10 @@ import GeometryType from '../geom/GeometryType.js';
import MultiPoint from '../geom/MultiPoint.js'; import MultiPoint from '../geom/MultiPoint.js';
import Polygon from '../geom/Polygon.js'; import Polygon from '../geom/Polygon.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
import _ol_geom_flat_area_ from '../geom/flat/area.js'; import {linearRingss as linearRingssArea} from '../geom/flat/area.js';
import _ol_geom_flat_center_ from '../geom/flat/center.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js';
import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
import _ol_geom_flat_contains_ from '../geom/flat/contains.js'; import {linearRingssContainsXY} from '../geom/flat/contains.js';
import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js';
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
@@ -151,8 +151,7 @@ MultiPolygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredD
* @inheritDoc * @inheritDoc
*/ */
MultiPolygon.prototype.containsXY = function(x, y) { MultiPolygon.prototype.containsXY = function(x, y) {
return _ol_geom_flat_contains_.linearRingssContainsXY( return linearRingssContainsXY(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
}; };
@@ -162,8 +161,7 @@ MultiPolygon.prototype.containsXY = function(x, y) {
* @api * @api
*/ */
MultiPolygon.prototype.getArea = function() { MultiPolygon.prototype.getArea = function() {
return _ol_geom_flat_area_.linearRingss( return linearRingssArea(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
}; };
@@ -209,7 +207,7 @@ MultiPolygon.prototype.getEndss = function() {
*/ */
MultiPolygon.prototype.getFlatInteriorPoints = function() { MultiPolygon.prototype.getFlatInteriorPoints = function() {
if (this.flatInteriorPointsRevision_ != this.getRevision()) { if (this.flatInteriorPointsRevision_ != this.getRevision()) {
const flatCenters = _ol_geom_flat_center_.linearRingss( const flatCenters = linearRingssCenter(
this.flatCoordinates, 0, this.endss_, this.stride); this.flatCoordinates, 0, this.endss_, this.stride);
this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRingss( this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRingss(
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
+4 -6
View File
@@ -10,9 +10,9 @@ import LinearRing from '../geom/LinearRing.js';
import Point from '../geom/Point.js'; import Point from '../geom/Point.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
import {offset as sphereOffset} from '../sphere.js'; import {offset as sphereOffset} from '../sphere.js';
import _ol_geom_flat_area_ from '../geom/flat/area.js'; import {linearRings as linearRingsArea} from '../geom/flat/area.js';
import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
import _ol_geom_flat_contains_ from '../geom/flat/contains.js'; import {linearRingsContainsXY} from '../geom/flat/contains.js';
import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js';
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
@@ -141,8 +141,7 @@ Polygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistan
* @inheritDoc * @inheritDoc
*/ */
Polygon.prototype.containsXY = function(x, y) { Polygon.prototype.containsXY = function(x, y) {
return _ol_geom_flat_contains_.linearRingsContainsXY( return linearRingsContainsXY(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
}; };
@@ -152,8 +151,7 @@ Polygon.prototype.containsXY = function(x, y) {
* @api * @api
*/ */
Polygon.prototype.getArea = function() { Polygon.prototype.getArea = function() {
return _ol_geom_flat_area_.linearRings( return linearRingsArea(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
}; };
+8 -10
View File
@@ -1,7 +1,6 @@
/** /**
* @module ol/geom/flat/area * @module ol/geom/flat/area
*/ */
const _ol_geom_flat_area_ = {};
/** /**
@@ -11,7 +10,7 @@ const _ol_geom_flat_area_ = {};
* @param {number} stride Stride. * @param {number} stride Stride.
* @return {number} Area. * @return {number} Area.
*/ */
_ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride) { export function linearRing(flatCoordinates, offset, end, stride) {
let twiceArea = 0; let twiceArea = 0;
let x1 = flatCoordinates[end - stride]; let x1 = flatCoordinates[end - stride];
let y1 = flatCoordinates[end - stride + 1]; let y1 = flatCoordinates[end - stride + 1];
@@ -23,7 +22,7 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride)
y1 = y2; y1 = y2;
} }
return twiceArea / 2; return twiceArea / 2;
}; }
/** /**
@@ -33,15 +32,15 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride)
* @param {number} stride Stride. * @param {number} stride Stride.
* @return {number} Area. * @return {number} Area.
*/ */
_ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride) { export function linearRings(flatCoordinates, offset, ends, stride) {
let area = 0; let area = 0;
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
area += _ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride); area += linearRing(flatCoordinates, offset, end, stride);
offset = end; offset = end;
} }
return area; return area;
}; }
/** /**
@@ -51,13 +50,12 @@ _ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride
* @param {number} stride Stride. * @param {number} stride Stride.
* @return {number} Area. * @return {number} Area.
*/ */
_ol_geom_flat_area_.linearRingss = function(flatCoordinates, offset, endss, stride) { export function linearRingss(flatCoordinates, offset, endss, stride) {
let area = 0; let area = 0;
for (let i = 0, ii = endss.length; i < ii; ++i) { for (let i = 0, ii = endss.length; i < ii; ++i) {
const ends = endss[i]; const ends = endss[i];
area += _ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride); area += linearRings(flatCoordinates, offset, ends, stride);
offset = ends[ends.length - 1]; offset = ends[ends.length - 1];
} }
return area; return area;
}; }
export default _ol_geom_flat_area_;
+2 -4
View File
@@ -2,7 +2,6 @@
* @module ol/geom/flat/center * @module ol/geom/flat/center
*/ */
import {createEmpty, createOrUpdateFromFlatCoordinates} from '../../extent.js'; import {createEmpty, createOrUpdateFromFlatCoordinates} from '../../extent.js';
const _ol_geom_flat_center_ = {};
/** /**
@@ -12,7 +11,7 @@ const _ol_geom_flat_center_ = {};
* @param {number} stride Stride. * @param {number} stride Stride.
* @return {Array.<number>} Flat centers. * @return {Array.<number>} Flat centers.
*/ */
_ol_geom_flat_center_.linearRingss = function(flatCoordinates, offset, endss, stride) { export function linearRingss(flatCoordinates, offset, endss, stride) {
const flatCenters = []; const flatCenters = [];
let extent = createEmpty(); let extent = createEmpty();
for (let i = 0, ii = endss.length; i < ii; ++i) { for (let i = 0, ii = endss.length; i < ii; ++i) {
@@ -22,5 +21,4 @@ _ol_geom_flat_center_.linearRingss = function(flatCoordinates, offset, endss, st
offset = ends[ends.length - 1]; offset = ends[ends.length - 1];
} }
return flatCenters; return flatCenters;
}; }
export default _ol_geom_flat_center_;
+15 -21
View File
@@ -2,7 +2,6 @@
* @module ol/geom/flat/contains * @module ol/geom/flat/contains
*/ */
import {forEachCorner} from '../../extent.js'; import {forEachCorner} from '../../extent.js';
const _ol_geom_flat_contains_ = {};
/** /**
@@ -13,18 +12,17 @@ const _ol_geom_flat_contains_ = {};
* @param {ol.Extent} extent Extent. * @param {ol.Extent} extent Extent.
* @return {boolean} Contains extent. * @return {boolean} Contains extent.
*/ */
_ol_geom_flat_contains_.linearRingContainsExtent = function(flatCoordinates, offset, end, stride, extent) { export function linearRingContainsExtent(flatCoordinates, offset, end, stride, extent) {
const outside = forEachCorner(extent, const outside = forEachCorner(extent,
/** /**
* @param {ol.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @return {boolean} Contains (x, y). * @return {boolean} Contains (x, y).
*/ */
function(coordinate) { function(coordinate) {
return !_ol_geom_flat_contains_.linearRingContainsXY(flatCoordinates, return !linearRingContainsXY(flatCoordinates, offset, end, stride, coordinate[0], coordinate[1]);
offset, end, stride, coordinate[0], coordinate[1]);
}); });
return !outside; return !outside;
}; }
/** /**
@@ -36,7 +34,7 @@ _ol_geom_flat_contains_.linearRingContainsExtent = function(flatCoordinates, off
* @param {number} y Y. * @param {number} y Y.
* @return {boolean} Contains (x, y). * @return {boolean} Contains (x, y).
*/ */
_ol_geom_flat_contains_.linearRingContainsXY = function(flatCoordinates, offset, end, stride, x, y) { export function linearRingContainsXY(flatCoordinates, offset, end, stride, x, y) {
// http://geomalgorithms.com/a03-_inclusion.html // http://geomalgorithms.com/a03-_inclusion.html
// Copyright 2000 softSurfer, 2012 Dan Sunday // Copyright 2000 softSurfer, 2012 Dan Sunday
// This code may be freely used and modified for any purpose // This code may be freely used and modified for any purpose
@@ -61,7 +59,7 @@ _ol_geom_flat_contains_.linearRingContainsXY = function(flatCoordinates, offset,
y1 = y2; y1 = y2;
} }
return wn !== 0; return wn !== 0;
}; }
/** /**
@@ -73,22 +71,20 @@ _ol_geom_flat_contains_.linearRingContainsXY = function(flatCoordinates, offset,
* @param {number} y Y. * @param {number} y Y.
* @return {boolean} Contains (x, y). * @return {boolean} Contains (x, y).
*/ */
_ol_geom_flat_contains_.linearRingsContainsXY = function(flatCoordinates, offset, ends, stride, x, y) { export function linearRingsContainsXY(flatCoordinates, offset, ends, stride, x, y) {
if (ends.length === 0) { if (ends.length === 0) {
return false; return false;
} }
if (!_ol_geom_flat_contains_.linearRingContainsXY( if (!linearRingContainsXY(flatCoordinates, offset, ends[0], stride, x, y)) {
flatCoordinates, offset, ends[0], stride, x, y)) {
return false; return false;
} }
for (let i = 1, ii = ends.length; i < ii; ++i) { for (let i = 1, ii = ends.length; i < ii; ++i) {
if (_ol_geom_flat_contains_.linearRingContainsXY( if (linearRingContainsXY(flatCoordinates, ends[i - 1], ends[i], stride, x, y)) {
flatCoordinates, ends[i - 1], ends[i], stride, x, y)) {
return false; return false;
} }
} }
return true; return true;
}; }
/** /**
@@ -100,18 +96,16 @@ _ol_geom_flat_contains_.linearRingsContainsXY = function(flatCoordinates, offset
* @param {number} y Y. * @param {number} y Y.
* @return {boolean} Contains (x, y). * @return {boolean} Contains (x, y).
*/ */
_ol_geom_flat_contains_.linearRingssContainsXY = function(flatCoordinates, offset, endss, stride, x, y) { export function linearRingssContainsXY(flatCoordinates, offset, endss, stride, x, y) {
if (endss.length === 0) { if (endss.length === 0) {
return false; return false;
} }
for (let i = 0, ii = endss.length; i < ii; ++i) { for (let i = 0, ii = endss.length; i < ii; ++i) {
const ends = endss[i]; const ends = endss[i];
if (_ol_geom_flat_contains_.linearRingsContainsXY( if (linearRingsContainsXY(flatCoordinates, offset, ends, stride, x, y)) {
flatCoordinates, offset, ends, stride, x, y)) {
return true; return true;
} }
offset = ends[ends.length - 1]; offset = ends[ends.length - 1];
} }
return false; return false;
}; }
export default _ol_geom_flat_contains_;
+2 -4
View File
@@ -1,7 +1,6 @@
/** /**
* @module ol/geom/flat/flip * @module ol/geom/flat/flip
*/ */
const _ol_geom_flat_flip_ = {};
/** /**
@@ -13,7 +12,7 @@ const _ol_geom_flat_flip_ = {};
* @param {number=} opt_destOffset Destination offset. * @param {number=} opt_destOffset Destination offset.
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
_ol_geom_flat_flip_.flipXY = function(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) { export function flipXY(flatCoordinates, offset, end, stride, opt_dest, opt_destOffset) {
let dest, destOffset; let dest, destOffset;
if (opt_dest !== undefined) { if (opt_dest !== undefined) {
dest = opt_dest; dest = opt_dest;
@@ -33,5 +32,4 @@ _ol_geom_flat_flip_.flipXY = function(flatCoordinates, offset, end, stride, opt_
} }
dest.length = destOffset; dest.length = destOffset;
return dest; return dest;
}; }
export default _ol_geom_flat_flip_;
+28 -33
View File
@@ -3,18 +3,16 @@
*/ */
import {squaredSegmentDistance, toRadians, toDegrees} from '../../math.js'; import {squaredSegmentDistance, toRadians, toDegrees} from '../../math.js';
import {get as getProjection, getTransform} from '../../proj.js'; import {get as getProjection, getTransform} from '../../proj.js';
const _ol_geom_flat_geodesic_ = {};
/** /**
* @private
* @param {function(number): ol.Coordinate} interpolate Interpolate function. * @param {function(number): ol.Coordinate} interpolate Interpolate function.
* @param {ol.TransformFunction} transform Transform from longitude/latitude to * @param {ol.TransformFunction} transform Transform from longitude/latitude to
* projected coordinates. * projected coordinates.
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
_ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredTolerance) { function line(interpolate, transform, squaredTolerance) {
// FIXME reduce garbage generation // FIXME reduce garbage generation
// FIXME optimize stack operations // FIXME optimize stack operations
@@ -77,22 +75,20 @@ _ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredToleranc
} }
return flatCoordinates; return flatCoordinates;
}; }
/** /**
* Generate a great-circle arcs between two lat/lon points. * Generate a great-circle arcs between two lat/lon points.
* @param {number} lon1 Longitude 1 in degrees. * @param {number} lon1 Longitude 1 in degrees.
* @param {number} lat1 Latitude 1 in degrees. * @param {number} lat1 Latitude 1 in degrees.
* @param {number} lon2 Longitude 2 in degrees. * @param {number} lon2 Longitude 2 in degrees.
* @param {number} lat2 Latitude 2 in degrees. * @param {number} lat2 Latitude 2 in degrees.
* @param {ol.proj.Projection} projection Projection. * @param {ol.proj.Projection} projection Projection.
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
_ol_geom_flat_geodesic_.greatCircleArc = function( export function greatCircleArc(lon1, lat1, lon2, lat2, projection, squaredTolerance) {
lon1, lat1, lon2, lat2, projection, squaredTolerance) {
const geoProjection = getProjection('EPSG:4326'); const geoProjection = getProjection('EPSG:4326');
const cosLat1 = Math.cos(toRadians(lat1)); const cosLat1 = Math.cos(toRadians(lat1));
@@ -103,11 +99,11 @@ _ol_geom_flat_geodesic_.greatCircleArc = function(
const sinDeltaLon = Math.sin(toRadians(lon2 - lon1)); const sinDeltaLon = Math.sin(toRadians(lon2 - lon1));
const d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon; const d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon;
return _ol_geom_flat_geodesic_.line_( return line(
/** /**
* @param {number} frac Fraction. * @param {number} frac Fraction.
* @return {ol.Coordinate} Coordinate. * @return {ol.Coordinate} Coordinate.
*/ */
function(frac) { function(frac) {
if (1 <= d) { if (1 <= d) {
return [lon2, lat2]; return [lon2, lat2];
@@ -124,7 +120,7 @@ _ol_geom_flat_geodesic_.greatCircleArc = function(
cosD - sinLat1 * Math.sin(lat)); cosD - sinLat1 * Math.sin(lat));
return [toDegrees(lon), toDegrees(lat)]; return [toDegrees(lon), toDegrees(lat)];
}, getTransform(geoProjection, projection), squaredTolerance); }, getTransform(geoProjection, projection), squaredTolerance);
}; }
/** /**
@@ -136,18 +132,18 @@ _ol_geom_flat_geodesic_.greatCircleArc = function(
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
_ol_geom_flat_geodesic_.meridian = function(lon, lat1, lat2, projection, squaredTolerance) { export function meridian(lon, lat1, lat2, projection, squaredTolerance) {
const epsg4326Projection = getProjection('EPSG:4326'); const epsg4326Projection = getProjection('EPSG:4326');
return _ol_geom_flat_geodesic_.line_( return line(
/** /**
* @param {number} frac Fraction. * @param {number} frac Fraction.
* @return {ol.Coordinate} Coordinate. * @return {ol.Coordinate} Coordinate.
*/ */
function(frac) { function(frac) {
return [lon, lat1 + ((lat2 - lat1) * frac)]; return [lon, lat1 + ((lat2 - lat1) * frac)];
}, },
getTransform(epsg4326Projection, projection), squaredTolerance); getTransform(epsg4326Projection, projection), squaredTolerance);
}; }
/** /**
@@ -159,16 +155,15 @@ _ol_geom_flat_geodesic_.meridian = function(lon, lat1, lat2, projection, squared
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @return {Array.<number>} Flat coordinates. * @return {Array.<number>} Flat coordinates.
*/ */
_ol_geom_flat_geodesic_.parallel = function(lat, lon1, lon2, projection, squaredTolerance) { export function parallel(lat, lon1, lon2, projection, squaredTolerance) {
const epsg4326Projection = getProjection('EPSG:4326'); const epsg4326Projection = getProjection('EPSG:4326');
return _ol_geom_flat_geodesic_.line_( return line(
/** /**
* @param {number} frac Fraction. * @param {number} frac Fraction.
* @return {ol.Coordinate} Coordinate. * @return {ol.Coordinate} Coordinate.
*/ */
function(frac) { function(frac) {
return [lon1 + ((lon2 - lon1) * frac), lat]; return [lon1 + ((lon2 - lon1) * frac), lat];
}, },
getTransform(epsg4326Projection, projection), squaredTolerance); getTransform(epsg4326Projection, projection), squaredTolerance);
}; }
export default _ol_geom_flat_geodesic_;
+2 -3
View File
@@ -2,7 +2,7 @@
* @module ol/geom/flat/interiorpoint * @module ol/geom/flat/interiorpoint
*/ */
import {numberSafeCompareFunction} from '../../array.js'; import {numberSafeCompareFunction} from '../../array.js';
import _ol_geom_flat_contains_ from '../flat/contains.js'; import {linearRingsContainsXY} from '../flat/contains.js';
const _ol_geom_flat_interiorpoint_ = {}; const _ol_geom_flat_interiorpoint_ = {};
@@ -52,8 +52,7 @@ _ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset,
const segmentLength = Math.abs(x2 - x1); const segmentLength = Math.abs(x2 - x1);
if (segmentLength > maxSegmentLength) { if (segmentLength > maxSegmentLength) {
x = (x1 + x2) / 2; x = (x1 + x2) / 2;
if (_ol_geom_flat_contains_.linearRingsContainsXY( if (linearRingsContainsXY(flatCoordinates, offset, ends, stride, x, y)) {
flatCoordinates, offset, ends, stride, x, y)) {
pointX = x; pointX = x;
maxSegmentLength = segmentLength; maxSegmentLength = segmentLength;
} }
+13 -18
View File
@@ -2,8 +2,8 @@
* @module ol/geom/flat/intersectsextent * @module ol/geom/flat/intersectsextent
*/ */
import {containsExtent, createEmpty, extendFlatCoordinates, intersects, intersectsSegment} from '../../extent.js'; import {containsExtent, createEmpty, extendFlatCoordinates, intersects, intersectsSegment} from '../../extent.js';
import _ol_geom_flat_contains_ from '../flat/contains.js'; import {linearRingContainsXY, linearRingContainsExtent} from '../flat/contains.js';
import _ol_geom_flat_segments_ from '../flat/segments.js'; import {forEach as forEachSegment} from '../flat/segments.js';
const _ol_geom_flat_intersectsextent_ = {}; const _ol_geom_flat_intersectsextent_ = {};
@@ -32,13 +32,13 @@ _ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, e
coordinatesExtent[3] <= extent[3]) { coordinatesExtent[3] <= extent[3]) {
return true; return true;
} }
return _ol_geom_flat_segments_.forEach(flatCoordinates, offset, end, stride, return forEachSegment(flatCoordinates, offset, end, stride,
/** /**
* @param {ol.Coordinate} point1 Start point. * @param {ol.Coordinate} point1 Start point.
* @param {ol.Coordinate} point2 End point. * @param {ol.Coordinate} point2 End point.
* @return {boolean} `true` if the segment and the extent intersect, * @return {boolean} `true` if the segment and the extent intersect,
* `false` otherwise. * `false` otherwise.
*/ */
function(point1, point2) { function(point1, point2) {
return intersectsSegment(extent, point1, point2); return intersectsSegment(extent, point1, point2);
}); });
@@ -78,20 +78,16 @@ _ol_geom_flat_intersectsextent_.linearRing = function(flatCoordinates, offset, e
flatCoordinates, offset, end, stride, extent)) { flatCoordinates, offset, end, stride, extent)) {
return true; return true;
} }
if (_ol_geom_flat_contains_.linearRingContainsXY( if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[0], extent[1])) {
flatCoordinates, offset, end, stride, extent[0], extent[1])) {
return true; return true;
} }
if (_ol_geom_flat_contains_.linearRingContainsXY( if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[0], extent[3])) {
flatCoordinates, offset, end, stride, extent[0], extent[3])) {
return true; return true;
} }
if (_ol_geom_flat_contains_.linearRingContainsXY( if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[2], extent[1])) {
flatCoordinates, offset, end, stride, extent[2], extent[1])) {
return true; return true;
} }
if (_ol_geom_flat_contains_.linearRingContainsXY( if (linearRingContainsXY(flatCoordinates, offset, end, stride, extent[2], extent[3])) {
flatCoordinates, offset, end, stride, extent[2], extent[3])) {
return true; return true;
} }
return false; return false;
@@ -115,8 +111,7 @@ _ol_geom_flat_intersectsextent_.linearRings = function(flatCoordinates, offset,
return true; return true;
} }
for (let i = 1, ii = ends.length; i < ii; ++i) { for (let i = 1, ii = ends.length; i < ii; ++i) {
if (_ol_geom_flat_contains_.linearRingContainsExtent( if (linearRingContainsExtent(flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
flatCoordinates, ends[i - 1], ends[i], stride, extent)) {
return false; return false;
} }
} }
+2 -2
View File
@@ -1,7 +1,7 @@
/** /**
* @module ol/geom/flat/orient * @module ol/geom/flat/orient
*/ */
import _ol_geom_flat_reverse_ from '../flat/reverse.js'; import {coordinates as reverseCoordinates} from '../flat/reverse.js';
const _ol_geom_flat_orient_ = {}; const _ol_geom_flat_orient_ = {};
@@ -110,7 +110,7 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends
(right && isClockwise) || (!right && !isClockwise) : (right && isClockwise) || (!right && !isClockwise) :
(right && !isClockwise) || (!right && isClockwise); (right && !isClockwise) || (!right && isClockwise);
if (reverse) { if (reverse) {
_ol_geom_flat_reverse_.coordinates(flatCoordinates, offset, end, stride); reverseCoordinates(flatCoordinates, offset, end, stride);
} }
offset = end; offset = end;
} }
+2 -4
View File
@@ -1,7 +1,6 @@
/** /**
* @module ol/geom/flat/reverse * @module ol/geom/flat/reverse
*/ */
const _ol_geom_flat_reverse_ = {};
/** /**
@@ -10,7 +9,7 @@ const _ol_geom_flat_reverse_ = {};
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
*/ */
_ol_geom_flat_reverse_.coordinates = function(flatCoordinates, offset, end, stride) { export function coordinates(flatCoordinates, offset, end, stride) {
while (offset < end - stride) { while (offset < end - stride) {
for (let i = 0; i < stride; ++i) { for (let i = 0; i < stride; ++i) {
const tmp = flatCoordinates[offset + i]; const tmp = flatCoordinates[offset + i];
@@ -20,5 +19,4 @@ _ol_geom_flat_reverse_.coordinates = function(flatCoordinates, offset, end, stri
offset += stride; offset += stride;
end -= stride; end -= stride;
} }
}; }
export default _ol_geom_flat_reverse_;
+2 -4
View File
@@ -1,7 +1,6 @@
/** /**
* @module ol/geom/flat/segments * @module ol/geom/flat/segments
*/ */
const _ol_geom_flat_segments_ = {};
/** /**
@@ -19,7 +18,7 @@ const _ol_geom_flat_segments_ = {};
* @return {T|boolean} Value. * @return {T|boolean} Value.
* @template T,S * @template T,S
*/ */
_ol_geom_flat_segments_.forEach = function(flatCoordinates, offset, end, stride, callback, opt_this) { export function forEach(flatCoordinates, offset, end, stride, callback, opt_this) {
const point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]]; const point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]];
const point2 = []; const point2 = [];
let ret; let ret;
@@ -34,5 +33,4 @@ _ol_geom_flat_segments_.forEach = function(flatCoordinates, offset, end, stride,
point1[1] = point2[1]; point1[1] = point2[1];
} }
return false; return false;
}; }
export default _ol_geom_flat_segments_;
+4 -6
View File
@@ -1,8 +1,7 @@
/** /**
* @module ol/geom/flat/topology * @module ol/geom/flat/topology
*/ */
import _ol_geom_flat_area_ from '../flat/area.js'; import {linearRing as linearRingArea} from '../flat/area.js';
const _ol_geom_flat_topology_ = {};
/** /**
* Check if the linestring is a boundary. * Check if the linestring is a boundary.
@@ -12,12 +11,11 @@ const _ol_geom_flat_topology_ = {};
* @param {number} stride Stride. * @param {number} stride Stride.
* @return {boolean} The linestring is a boundary. * @return {boolean} The linestring is a boundary.
*/ */
_ol_geom_flat_topology_.lineStringIsClosed = function(flatCoordinates, offset, end, stride) { export function lineStringIsClosed(flatCoordinates, offset, end, stride) {
const lastCoord = end - stride; const lastCoord = end - stride;
if (flatCoordinates[offset] === flatCoordinates[lastCoord] && if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) { flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
return !!_ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride); return !!linearRingArea(flatCoordinates, offset, end, stride);
} }
return false; return false;
}; }
export default _ol_geom_flat_topology_;
+8 -8
View File
@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import _ol_coordinate_ from '../coordinate.js'; import _ol_coordinate_ from '../coordinate.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import _ol_events_KeyCode_ from '../events/KeyCode.js'; import KeyCode from '../events/KeyCode.js';
import _ol_events_condition_ from '../events/condition.js'; import _ol_events_condition_ from '../events/condition.js';
import Interaction from '../interaction/Interaction.js'; import Interaction from '../interaction/Interaction.js';
@@ -82,19 +82,19 @@ KeyboardPan.handleEvent = function(mapBrowserEvent) {
const keyEvent = mapBrowserEvent.originalEvent; const keyEvent = mapBrowserEvent.originalEvent;
const keyCode = keyEvent.keyCode; const keyCode = keyEvent.keyCode;
if (this.condition_(mapBrowserEvent) && if (this.condition_(mapBrowserEvent) &&
(keyCode == _ol_events_KeyCode_.DOWN || (keyCode == KeyCode.DOWN ||
keyCode == _ol_events_KeyCode_.LEFT || keyCode == KeyCode.LEFT ||
keyCode == _ol_events_KeyCode_.RIGHT || keyCode == KeyCode.RIGHT ||
keyCode == _ol_events_KeyCode_.UP)) { keyCode == KeyCode.UP)) {
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const view = map.getView(); const view = map.getView();
const mapUnitsDelta = view.getResolution() * this.pixelDelta_; const mapUnitsDelta = view.getResolution() * this.pixelDelta_;
let deltaX = 0, deltaY = 0; let deltaX = 0, deltaY = 0;
if (keyCode == _ol_events_KeyCode_.DOWN) { if (keyCode == KeyCode.DOWN) {
deltaY = -mapUnitsDelta; deltaY = -mapUnitsDelta;
} else if (keyCode == _ol_events_KeyCode_.LEFT) { } else if (keyCode == KeyCode.LEFT) {
deltaX = -mapUnitsDelta; deltaX = -mapUnitsDelta;
} else if (keyCode == _ol_events_KeyCode_.RIGHT) { } else if (keyCode == KeyCode.RIGHT) {
deltaX = mapUnitsDelta; deltaX = mapUnitsDelta;
} else { } else {
deltaY = mapUnitsDelta; deltaY = mapUnitsDelta;
+2 -2
View File
@@ -5,7 +5,7 @@ import {nullFunction} from '../index.js';
import {extend} from '../array.js'; import {extend} from '../array.js';
import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCenter, getHeight} from '../extent.js'; import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCenter, getHeight} from '../extent.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import _ol_geom_flat_center_ from '../geom/flat/center.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js';
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; import _ol_geom_flat_transform_ from '../geom/flat/transform.js';
@@ -137,7 +137,7 @@ RenderFeature.prototype.getFlatInteriorPoint = function() {
*/ */
RenderFeature.prototype.getFlatInteriorPoints = function() { RenderFeature.prototype.getFlatInteriorPoints = function() {
if (!this.flatInteriorPoints_) { if (!this.flatInteriorPoints_) {
const flatCenters = _ol_geom_flat_center_.linearRingss( const flatCenters = linearRingssCenter(
this.flatCoordinates_, 0, this.ends_, 2); this.flatCoordinates_, 0, this.ends_, 2);
this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRingss( this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRingss(
this.flatCoordinates_, 0, this.ends_, 2, flatCenters); this.flatCoordinates_, 0, this.ends_, 2, flatCenters);
+4 -6
View File
@@ -7,7 +7,7 @@ import {asArray} from '../../color.js';
import {intersects} from '../../extent.js'; import {intersects} from '../../extent.js';
import _ol_geom_flat_orient_ from '../../geom/flat/orient.js'; import _ol_geom_flat_orient_ from '../../geom/flat/orient.js';
import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js';
import _ol_geom_flat_topology_ from '../../geom/flat/topology.js'; import {lineStringIsClosed} from '../../geom/flat/topology.js';
import {isEmpty} from '../../obj.js'; import {isEmpty} from '../../obj.js';
import _ol_render_webgl_ from '../webgl.js'; import _ol_render_webgl_ from '../webgl.js';
import WebGLReplay from '../webgl/Replay.js'; import WebGLReplay from '../webgl/Replay.js';
@@ -91,7 +91,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off
this.state_.lineJoin === 'miter' ? 1 : 2; this.state_.lineJoin === 'miter' ? 1 : 2;
const lineCap = this.state_.lineCap === 'butt' ? 0 : const lineCap = this.state_.lineCap === 'butt' ? 0 :
this.state_.lineCap === 'square' ? 1 : 2; this.state_.lineCap === 'square' ? 1 : 2;
const closed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, offset, end, stride); const closed = lineStringIsClosed(flatCoordinates, offset, end, stride);
let startCoords, sign, n; let startCoords, sign, n;
let lastIndex = numIndices; let lastIndex = numIndices;
let lastSign = 1; let lastSign = 1;
@@ -357,8 +357,7 @@ WebGLLineStringReplay.prototype.drawMultiLineString = function(multiLineStringGe
*/ */
WebGLLineStringReplay.prototype.drawPolygonCoordinates = function( WebGLLineStringReplay.prototype.drawPolygonCoordinates = function(
flatCoordinates, holeFlatCoordinates, stride) { flatCoordinates, holeFlatCoordinates, stride) {
if (!_ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, if (!lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, stride)) {
flatCoordinates.length, stride)) {
flatCoordinates.push(flatCoordinates[0]); flatCoordinates.push(flatCoordinates[0]);
flatCoordinates.push(flatCoordinates[1]); flatCoordinates.push(flatCoordinates[1]);
} }
@@ -366,8 +365,7 @@ WebGLLineStringReplay.prototype.drawPolygonCoordinates = function(
if (holeFlatCoordinates.length) { if (holeFlatCoordinates.length) {
let i, ii; let i, ii;
for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) { for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
if (!_ol_geom_flat_topology_.lineStringIsClosed(holeFlatCoordinates[i], 0, if (!lineStringIsClosed(holeFlatCoordinates[i], 0, holeFlatCoordinates[i].length, stride)) {
holeFlatCoordinates[i].length, stride)) {
holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]); holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]);
holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]); holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]);
} }
+2 -3
View File
@@ -6,7 +6,7 @@ import {equals} from '../../array.js';
import {asArray} from '../../color.js'; import {asArray} from '../../color.js';
import {intersects} from '../../extent.js'; import {intersects} from '../../extent.js';
import {isEmpty} from '../../obj.js'; import {isEmpty} from '../../obj.js';
import _ol_geom_flat_contains_ from '../../geom/flat/contains.js'; import {linearRingContainsXY} from '../../geom/flat/contains.js';
import _ol_geom_flat_orient_ from '../../geom/flat/orient.js'; import _ol_geom_flat_orient_ from '../../geom/flat/orient.js';
import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js';
import _ol_render_webgl_polygonreplay_defaultshader_ from '../webgl/polygonreplay/defaultshader.js'; import _ol_render_webgl_polygonreplay_defaultshader_ from '../webgl/polygonreplay/defaultshader.js';
@@ -663,8 +663,7 @@ WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, p2, rtree,
if (typeof p === 'object' && (!opt_reflex || p.reflex)) { if (typeof p === 'object' && (!opt_reflex || p.reflex)) {
if ((p.x !== p0.x || p.y !== p0.y) && (p.x !== p1.x || p.y !== p1.y) && if ((p.x !== p0.x || p.y !== p0.y) && (p.x !== p1.x || p.y !== p1.y) &&
(p.x !== p2.x || p.y !== p2.y) && result.indexOf(p) === -1 && (p.x !== p2.x || p.y !== p2.y) && result.indexOf(p) === -1 &&
_ol_geom_flat_contains_.linearRingContainsXY([p0.x, p0.y, p1.x, p1.y, linearRingContainsXY([p0.x, p0.y, p1.x, p1.y, p2.x, p2.y], 0, 6, 2, p.x, p.y)) {
p2.x, p2.y], 0, 6, 2, p.x, p.y)) {
result.push(p); result.push(p);
} }
} }
+4 -5
View File
@@ -1,17 +1,16 @@
import _ol_geom_flat_area_ from '../../../../../src/ol/geom/flat/area.js'; import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js';
describe('ol.geom.flat.area', function() { describe('ol.geom.flat.area', function() {
describe('ol.geom.flat.area.linearRing', function() { describe('ol.geom.flat.area.linearRing', function() {
it('calculates the area of a triangle', function() { it('calculates the area of a triangle', function() {
const area = _ol_geom_flat_area_.linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2); const area = linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
expect(area).to.be(0.5); expect(area).to.be(0.5);
}); });
it('calculates the area of a unit square', function() { it('calculates the area of a unit square', function() {
const area = const area = linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
_ol_geom_flat_area_.linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
expect(area).to.be(1); expect(area).to.be(1);
}); });
@@ -20,7 +19,7 @@ describe('ol.geom.flat.area', function() {
describe('ol.geom.flat.area.linearRings', function() { describe('ol.geom.flat.area.linearRings', function() {
it('calculates the area with holes', function() { it('calculates the area with holes', function() {
const area = _ol_geom_flat_area_.linearRings( const area = linearRings(
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2); [0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2);
expect(area).to.be(8); expect(area).to.be(8);
}); });
+4 -4
View File
@@ -1,4 +1,4 @@
import _ol_geom_flat_center_ from '../../../../../src/ol/geom/flat/center.js'; import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js'; import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
@@ -10,7 +10,7 @@ describe('ol.geom.flat.center', function() {
const squareMultiPoly = new MultiPolygon([[ const squareMultiPoly = new MultiPolygon([[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]] [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
]]); ]]);
const got = _ol_geom_flat_center_.linearRingss( const got = linearRingssCenter(
squareMultiPoly.flatCoordinates, squareMultiPoly.flatCoordinates,
0, 0,
squareMultiPoly.endss_, squareMultiPoly.endss_,
@@ -28,7 +28,7 @@ describe('ol.geom.flat.center', function() {
[[3, 0], [3, 1], [4, 1], [4, 0], [3, 0]] [[3, 0], [3, 1], [4, 1], [4, 0], [3, 0]]
] ]
]); ]);
const got = _ol_geom_flat_center_.linearRingss( const got = linearRingssCenter(
squareMultiPoly.flatCoordinates, squareMultiPoly.flatCoordinates,
0, 0,
squareMultiPoly.endss_, squareMultiPoly.endss_,
@@ -42,7 +42,7 @@ describe('ol.geom.flat.center', function() {
[[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]], [[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]],
[[1, 1], [1, 4], [4, 4], [4, 1], [1, 1]] [[1, 1], [1, 4], [4, 4], [4, 1], [1, 1]]
]]); ]]);
const got = _ol_geom_flat_center_.linearRingss( const got = linearRingssCenter(
polywithHole.flatCoordinates, polywithHole.flatCoordinates,
0, 0,
polywithHole.endss_, polywithHole.endss_,
+6 -6
View File
@@ -1,4 +1,4 @@
import _ol_geom_flat_contains_ from '../../../../../src/ol/geom/flat/contains.js'; import {linearRingContainsXY} from '../../../../../src/ol/geom/flat/contains.js';
describe('ol.geom.flat.contains', function() { describe('ol.geom.flat.contains', function() {
@@ -11,27 +11,27 @@ describe('ol.geom.flat.contains', function() {
describe('ol.geom.flat.contains.linearRingContainsXY', function() { describe('ol.geom.flat.contains.linearRingContainsXY', function() {
it('returns true for point inside a simple polygon', function() { it('returns true for point inside a simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY( expect(linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true); flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true);
}); });
it('returns false for point outside a simple polygon', function() { it('returns false for point outside a simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY( expect(linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false); flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false);
}); });
it('returns true for point inside a non-simple polygon', function() { it('returns true for point inside a non-simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY( expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true); flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true);
}); });
it('returns true for point inside an overlap of a non-simple polygon', function() { it('returns true for point inside an overlap of a non-simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY( expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true); flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true);
}); });
it('returns false for a point inside a hole of a non-simple polygon', function() { it('returns false for a point inside a hole of a non-simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY( expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false); flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false);
}); });
+5 -9
View File
@@ -1,4 +1,4 @@
import _ol_geom_flat_flip_ from '../../../../../src/ol/geom/flat/flip.js'; import {flipXY} from '../../../../../src/ol/geom/flat/flip.js';
describe('ol.geom.flat.flip', function() { describe('ol.geom.flat.flip', function() {
@@ -6,29 +6,25 @@ describe('ol.geom.flat.flip', function() {
describe('ol.geom.flat.flip.flipXY', function() { describe('ol.geom.flat.flip.flipXY', function() {
it('can flip XY coordinates', function() { it('can flip XY coordinates', function() {
const flatCoordinates = _ol_geom_flat_flip_.flipXY([1, 2, 3, 4], 0, 4, 2); const flatCoordinates = flipXY([1, 2, 3, 4], 0, 4, 2);
expect(flatCoordinates).to.eql([2, 1, 4, 3]); expect(flatCoordinates).to.eql([2, 1, 4, 3]);
}); });
it('can flip XY coordinates while preserving other dimensions', function() { it('can flip XY coordinates while preserving other dimensions', function() {
const flatCoordinates = _ol_geom_flat_flip_.flipXY( const flatCoordinates = flipXY([1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
[1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
expect(flatCoordinates).to.eql([2, 1, 3, 4, 6, 5, 7, 8]); expect(flatCoordinates).to.eql([2, 1, 3, 4, 6, 5, 7, 8]);
}); });
it('can flip XY coordinates in place', function() { it('can flip XY coordinates in place', function() {
const flatCoordinates = [1, 2, 3, 4]; const flatCoordinates = [1, 2, 3, 4];
expect(_ol_geom_flat_flip_.flipXY( expect(flipXY(flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 4, 3]); expect(flatCoordinates).to.eql([2, 1, 4, 3]);
}); });
it('can flip XY coordinates in place while preserving other dimensions', it('can flip XY coordinates in place while preserving other dimensions',
function() { function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(_ol_geom_flat_flip_.flipXY( expect(flipXY(flatCoordinates, 0, 9, 3, flatCoordinates)).to.be(flatCoordinates);
flatCoordinates, 0, 9, 3, flatCoordinates)).
to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]); expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
}); });
+16 -31
View File
@@ -1,4 +1,4 @@
import _ol_geom_flat_reverse_ from '../../../../../src/ol/geom/flat/reverse.js'; import {coordinates as reverseCoordinates} from '../../../../../src/ol/geom/flat/reverse.js';
describe('ol.geom.flat.reverse', function() { describe('ol.geom.flat.reverse', function() {
@@ -9,36 +9,31 @@ describe('ol.geom.flat.reverse', function() {
it('can reverse empty flat coordinates', function() { it('can reverse empty flat coordinates', function() {
const flatCoordinates = []; const flatCoordinates = [];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.be.empty(); expect(flatCoordinates).to.be.empty();
}); });
it('can reverse one flat coordinates', function() { it('can reverse one flat coordinates', function() {
const flatCoordinates = [1, 2]; const flatCoordinates = [1, 2];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([1, 2]); expect(flatCoordinates).to.eql([1, 2]);
}); });
it('can reverse two flat coordinates', function() { it('can reverse two flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4]; const flatCoordinates = [1, 2, 3, 4];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([3, 4, 1, 2]); expect(flatCoordinates).to.eql([3, 4, 1, 2]);
}); });
it('can reverse three flat coordinates', function() { it('can reverse three flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6]; const flatCoordinates = [1, 2, 3, 4, 5, 6];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([5, 6, 3, 4, 1, 2]); expect(flatCoordinates).to.eql([5, 6, 3, 4, 1, 2]);
}); });
it('can reverse four flat coordinates', function() { it('can reverse four flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([7, 8, 5, 6, 3, 4, 1, 2]); expect(flatCoordinates).to.eql([7, 8, 5, 6, 3, 4, 1, 2]);
}); });
@@ -48,36 +43,31 @@ describe('ol.geom.flat.reverse', function() {
it('can reverse empty flat coordinates', function() { it('can reverse empty flat coordinates', function() {
const flatCoordinates = []; const flatCoordinates = [];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.be.empty(); expect(flatCoordinates).to.be.empty();
}); });
it('can reverse one flat coordinates', function() { it('can reverse one flat coordinates', function() {
const flatCoordinates = [1, 2, 3]; const flatCoordinates = [1, 2, 3];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([1, 2, 3]); expect(flatCoordinates).to.eql([1, 2, 3]);
}); });
it('can reverse two flat coordinates', function() { it('can reverse two flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6]; const flatCoordinates = [1, 2, 3, 4, 5, 6];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([4, 5, 6, 1, 2, 3]); expect(flatCoordinates).to.eql([4, 5, 6, 1, 2, 3]);
}); });
it('can reverse three flat coordinates', function() { it('can reverse three flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([7, 8, 9, 4, 5, 6, 1, 2, 3]); expect(flatCoordinates).to.eql([7, 8, 9, 4, 5, 6, 1, 2, 3]);
}); });
it('can reverse four flat coordinates', function() { it('can reverse four flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]); expect(flatCoordinates).to.eql([10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]);
}); });
@@ -87,37 +77,32 @@ describe('ol.geom.flat.reverse', function() {
it('can reverse empty flat coordinates', function() { it('can reverse empty flat coordinates', function() {
const flatCoordinates = []; const flatCoordinates = [];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.be.empty(); expect(flatCoordinates).to.be.empty();
}); });
it('can reverse one flat coordinates', function() { it('can reverse one flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4]; const flatCoordinates = [1, 2, 3, 4];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]); expect(flatCoordinates).to.eql([1, 2, 3, 4]);
}); });
it('can reverse two flat coordinates', function() { it('can reverse two flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([5, 6, 7, 8, 1, 2, 3, 4]); expect(flatCoordinates).to.eql([5, 6, 7, 8, 1, 2, 3, 4]);
}); });
it('can reverse three flat coordinates', function() { it('can reverse three flat coordinates', function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]); expect(flatCoordinates).to.eql([9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
}); });
it('can reverse four flat coordinates', function() { it('can reverse four flat coordinates', function() {
const flatCoordinates = const flatCoordinates =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
_ol_geom_flat_reverse_.coordinates( reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql( expect(flatCoordinates).to.eql(
[13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]); [13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
}); });
+3 -5
View File
@@ -1,4 +1,4 @@
import _ol_geom_flat_segments_ from '../../../../../src/ol/geom/flat/segments.js'; import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js';
describe('ol.geom.flat.segments', function() { describe('ol.geom.flat.segments', function() {
@@ -17,8 +17,7 @@ describe('ol.geom.flat.segments', function() {
const spy = sinon.spy(function(point1, point2) { const spy = sinon.spy(function(point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]); args.push([point1[0], point1[1], point2[0], point2[1]]);
}); });
const ret = _ol_geom_flat_segments_.forEach( const ret = forEachSegment(flatCoordinates, offset, end, stride, spy);
flatCoordinates, offset, end, stride, spy);
expect(spy.callCount).to.be(3); expect(spy.callCount).to.be(3);
expect(args[0][0]).to.be(0); expect(args[0][0]).to.be(0);
expect(args[0][1]).to.be(0); expect(args[0][1]).to.be(0);
@@ -42,8 +41,7 @@ describe('ol.geom.flat.segments', function() {
args.push([point1[0], point1[1], point2[0], point2[1]]); args.push([point1[0], point1[1], point2[0], point2[1]]);
return true; return true;
}); });
const ret = _ol_geom_flat_segments_.forEach( const ret = forEachSegment(flatCoordinates, offset, end, stride, spy);
flatCoordinates, offset, end, stride, spy);
expect(spy.callCount).to.be(1); expect(spy.callCount).to.be(1);
expect(args[0][0]).to.be(0); expect(args[0][0]).to.be(0);
expect(args[0][1]).to.be(0); expect(args[0][1]).to.be(0);
@@ -1,4 +1,4 @@
import _ol_geom_flat_topology_ from '../../../../../src/ol/geom/flat/topology.js'; import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js';
describe('ol.geom.flat.topology', function() { describe('ol.geom.flat.topology', function() {
@@ -6,23 +6,23 @@ describe('ol.geom.flat.topology', function() {
it('identifies closed lines aka boundaries', function() { it('identifies closed lines aka boundaries', function() {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0]; const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0];
const isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(true); expect(isClosed).to.be(true);
}); });
it('identifies regular linestrings', function() { it('identifies regular linestrings', function() {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2]; const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2];
const isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(false); expect(isClosed).to.be(false);
}); });
it('identifies degenerate boundaries', function() { it('identifies degenerate boundaries', function() {
let flatCoordinates = [0, 0, 3, 0, 0, 0]; let flatCoordinates = [0, 0, 3, 0, 0, 0];
let isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); let isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(false); expect(isClosed).to.be(false);
flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0]; flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0];
isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2); isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(false); expect(isClosed).to.be(false);
}); });