From fd78aa9798a73f7f956df0ae71a1cbf76b3ee579 Mon Sep 17 00:00:00 2001 From: raiyni Date: Mon, 12 Feb 2018 23:06:02 -0600 Subject: [PATCH 01/13] ol/geom/flate/inflate exports --- src/ol/format/Polyline.js | 4 ++-- src/ol/geom/LineString.js | 4 ++-- src/ol/geom/LinearRing.js | 4 ++-- src/ol/geom/MultiLineString.js | 4 ++-- src/ol/geom/MultiPoint.js | 4 ++-- src/ol/geom/MultiPolygon.js | 4 ++-- src/ol/geom/Polygon.js | 4 ++-- src/ol/geom/flat/inflate.js | 18 ++++++++---------- src/ol/render/canvas/Replay.js | 8 ++++---- test/spec/ol/geom/flat/inflate.test.js | 6 +++--- 10 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/ol/format/Polyline.js b/src/ol/format/Polyline.js index 7177da7519..43d07a73fc 100644 --- a/src/ol/format/Polyline.js +++ b/src/ol/format/Polyline.js @@ -10,7 +10,7 @@ import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import {getStrideForLayout} from '../geom/SimpleGeometry.js'; import {flipXY} from '../geom/flat/flip.js'; -import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; +import {inflateCoordinates} from '../geom/flat/inflate.js'; import {get as getProjection} from '../proj.js'; /** @@ -327,7 +327,7 @@ Polyline.prototype.readGeometryFromText = function(text, opt_options) { const stride = getStrideForLayout(this.geometryLayout_); const flatCoordinates = decodeDeltas(text, stride, this.factor_); flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates); - const coordinates = _ol_geom_flat_inflate_.coordinates( + const coordinates = inflateCoordinates( flatCoordinates, 0, flatCoordinates.length, stride); return ( diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 010e5f1cb5..da50f9bb0a 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -9,7 +9,7 @@ import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.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_inflate_ from '../geom/flat/inflate.js'; +import {inflateCoordinates} from '../geom/flat/inflate.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_length_ from '../geom/flat/length.js'; @@ -155,7 +155,7 @@ LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) { * @api */ LineString.prototype.getCoordinates = function() { - return _ol_geom_flat_inflate_.coordinates( + return inflateCoordinates( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride); }; diff --git a/src/ol/geom/LinearRing.js b/src/ol/geom/LinearRing.js index 56b98bb9f2..2acac977df 100644 --- a/src/ol/geom/LinearRing.js +++ b/src/ol/geom/LinearRing.js @@ -9,7 +9,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js'; import {linearRing as linearRingArea} from '../geom/flat/area.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_inflate_ from '../geom/flat/inflate.js'; +import {inflateCoordinates} from '../geom/flat/inflate.js'; import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; /** @@ -94,7 +94,7 @@ LinearRing.prototype.getArea = function() { * @api */ LinearRing.prototype.getCoordinates = function() { - return _ol_geom_flat_inflate_.coordinates( + return inflateCoordinates( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride); }; diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index 2a4e05cf71..1e6e2f4179 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -10,7 +10,7 @@ import LineString from '../geom/LineString.js'; import SimpleGeometry from '../geom/SimpleGeometry.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_inflate_ from '../geom/flat/inflate.js'; +import {inflateCoordinatesArray} from '../geom/flat/inflate.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_simplify_ from '../geom/flat/simplify.js'; @@ -144,7 +144,7 @@ MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_in * @api */ MultiLineString.prototype.getCoordinates = function() { - return _ol_geom_flat_inflate_.coordinatess( + return inflateCoordinatesArray( this.flatCoordinates, 0, this.ends_, this.stride); }; diff --git a/src/ol/geom/MultiPoint.js b/src/ol/geom/MultiPoint.js index a975a36da9..d5ed8a9ff0 100644 --- a/src/ol/geom/MultiPoint.js +++ b/src/ol/geom/MultiPoint.js @@ -9,7 +9,7 @@ import GeometryType from '../geom/GeometryType.js'; import Point from '../geom/Point.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; -import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; +import {inflateCoordinates} from '../geom/flat/inflate.js'; import {squaredDistance as squaredDx} from '../math.js'; /** @@ -89,7 +89,7 @@ MultiPoint.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis * @api */ MultiPoint.prototype.getCoordinates = function() { - return _ol_geom_flat_inflate_.coordinates( + return inflateCoordinates( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride); }; diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 32132422ef..a3b539b748 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -14,7 +14,7 @@ import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {linearRingssContainsXY} from '../geom/flat/contains.js'; import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; -import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; +import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; @@ -189,7 +189,7 @@ MultiPolygon.prototype.getCoordinates = function(opt_right) { flatCoordinates = this.flatCoordinates; } - return _ol_geom_flat_inflate_.coordinatesss( + return inflateMultiCoordinatesArray( flatCoordinates, 0, this.endss_, this.stride); }; diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 388b5ec39b..6620dbaf20 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -14,7 +14,7 @@ import {linearRings as linearRingsArea} from '../geom/flat/area.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {linearRingsContainsXY} from '../geom/flat/contains.js'; import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; -import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js'; +import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; @@ -179,7 +179,7 @@ Polygon.prototype.getCoordinates = function(opt_right) { flatCoordinates = this.flatCoordinates; } - return _ol_geom_flat_inflate_.coordinatess( + return inflateCoordinatesArray( flatCoordinates, 0, this.ends_, this.stride); }; diff --git a/src/ol/geom/flat/inflate.js b/src/ol/geom/flat/inflate.js index b95296c88c..fd7c2ba002 100644 --- a/src/ol/geom/flat/inflate.js +++ b/src/ol/geom/flat/inflate.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/inflate */ -const _ol_geom_flat_inflate_ = {}; /** @@ -12,7 +11,7 @@ const _ol_geom_flat_inflate_ = {}; * @param {Array.=} opt_coordinates Coordinates. * @return {Array.} Coordinates. */ -_ol_geom_flat_inflate_.coordinates = function(flatCoordinates, offset, end, stride, opt_coordinates) { +export function inflateCoordinates(flatCoordinates, offset, end, stride, opt_coordinates) { const coordinates = opt_coordinates !== undefined ? opt_coordinates : []; let i = 0; for (let j = offset; j < end; j += stride) { @@ -20,7 +19,7 @@ _ol_geom_flat_inflate_.coordinates = function(flatCoordinates, offset, end, stri } coordinates.length = i; return coordinates; -}; +} /** @@ -31,18 +30,18 @@ _ol_geom_flat_inflate_.coordinates = function(flatCoordinates, offset, end, stri * @param {Array.>=} opt_coordinatess Coordinatess. * @return {Array.>} Coordinatess. */ -_ol_geom_flat_inflate_.coordinatess = function(flatCoordinates, offset, ends, stride, opt_coordinatess) { +export function inflateCoordinatesArray(flatCoordinates, offset, ends, stride, opt_coordinatess) { const coordinatess = opt_coordinatess !== undefined ? opt_coordinatess : []; let i = 0; for (let j = 0, jj = ends.length; j < jj; ++j) { const end = ends[j]; - coordinatess[i++] = _ol_geom_flat_inflate_.coordinates( + coordinatess[i++] = inflateCoordinates( flatCoordinates, offset, end, stride, coordinatess[i]); offset = end; } coordinatess.length = i; return coordinatess; -}; +} /** @@ -54,16 +53,15 @@ _ol_geom_flat_inflate_.coordinatess = function(flatCoordinates, offset, ends, st * Coordinatesss. * @return {Array.>>} Coordinatesss. */ -_ol_geom_flat_inflate_.coordinatesss = function(flatCoordinates, offset, endss, stride, opt_coordinatesss) { +export function inflateMultiCoordinatesArray(flatCoordinates, offset, endss, stride, opt_coordinatesss) { const coordinatesss = opt_coordinatesss !== undefined ? opt_coordinatesss : []; let i = 0; for (let j = 0, jj = endss.length; j < jj; ++j) { const ends = endss[j]; - coordinatesss[i++] = _ol_geom_flat_inflate_.coordinatess( + coordinatesss[i++] = inflateCoordinatesArray( flatCoordinates, offset, ends, stride, coordinatesss[i]); offset = ends[ends.length - 1]; } coordinatesss.length = i; return coordinatesss; -}; -export default _ol_geom_flat_inflate_; +} diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index 6040f66905..329815acac 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -8,7 +8,7 @@ import {buffer, clone, coordinateRelationship, createEmpty, createOrUpdate, createOrUpdateEmpty, extend, extendCoordinate, intersects} from '../../extent.js'; import Relationship from '../../extent/Relationship.js'; import GeometryType from '../../geom/GeometryType.js'; -import _ol_geom_flat_inflate_ from '../../geom/flat/inflate.js'; +import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js'; import _ol_geom_flat_length_ from '../../geom/flat/length.js'; import _ol_geom_flat_textpath_ from '../../geom/flat/textpath.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; @@ -410,7 +410,7 @@ CanvasReplay.prototype.drawCustom = function(geometry, feature, renderer) { replayEndss.push(myEnds); } this.instructions.push([CanvasInstruction.CUSTOM, - replayBegin, replayEndss, geometry, renderer, _ol_geom_flat_inflate_.coordinatesss]); + replayBegin, replayEndss, geometry, renderer, inflateMultiCoordinatesArray]); } else if (type == GeometryType.POLYGON || type == GeometryType.MULTI_LINE_STRING) { replayEnds = []; flatCoordinates = (type == GeometryType.POLYGON) ? @@ -420,13 +420,13 @@ CanvasReplay.prototype.drawCustom = function(geometry, feature, renderer) { /** @type {ol.geom.Polygon|ol.geom.MultiLineString} */ (geometry).getEnds(), stride, replayEnds); this.instructions.push([CanvasInstruction.CUSTOM, - replayBegin, replayEnds, geometry, renderer, _ol_geom_flat_inflate_.coordinatess]); + replayBegin, replayEnds, geometry, renderer, inflateCoordinatesArray]); } else if (type == GeometryType.LINE_STRING || type == GeometryType.MULTI_POINT) { flatCoordinates = geometry.getFlatCoordinates(); replayEnd = this.appendFlatCoordinates( flatCoordinates, 0, flatCoordinates.length, stride, false, false); this.instructions.push([CanvasInstruction.CUSTOM, - replayBegin, replayEnd, geometry, renderer, _ol_geom_flat_inflate_.coordinates]); + replayBegin, replayEnd, geometry, renderer, inflateCoordinates]); } else if (type == GeometryType.POINT) { flatCoordinates = geometry.getFlatCoordinates(); this.coordinates.push(flatCoordinates[0], flatCoordinates[1]); diff --git a/test/spec/ol/geom/flat/inflate.test.js b/test/spec/ol/geom/flat/inflate.test.js index 13a7986ccb..356f5b87a2 100644 --- a/test/spec/ol/geom/flat/inflate.test.js +++ b/test/spec/ol/geom/flat/inflate.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_inflate_ from '../../../../../src/ol/geom/flat/inflate.js'; +import {inflateCoordinates, inflateCoordinatesArray} from '../../../../../src/ol/geom/flat/inflate.js'; describe('ol.geom.flat.inflate', function() { @@ -6,7 +6,7 @@ describe('ol.geom.flat.inflate', function() { describe('ol.geom.flat.inflate.coordinates', function() { it('inflates coordinates', function() { - const coordinates = _ol_geom_flat_inflate_.coordinates([1, 2, 3, 4], 0, 4, 2); + const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2); expect(coordinates).to.eql([[1, 2], [3, 4]]); }); @@ -15,7 +15,7 @@ describe('ol.geom.flat.inflate', function() { describe('ol.geom.flat.inflate.coordinatess', function() { it('inflates arrays of coordinates', function() { - const coordinatess = _ol_geom_flat_inflate_.coordinatess( + const coordinatess = inflateCoordinatesArray( [1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2); expect(coordinatess).to.eql([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]); }); From fb548b1b4501f4572242ce5384cb849481624e14 Mon Sep 17 00:00:00 2001 From: raiyni Date: Mon, 12 Feb 2018 23:18:53 -0600 Subject: [PATCH 02/13] ol/geom/flat/deflate exports --- src/ol/format/EsriJSON.js | 4 ++-- src/ol/geom/Circle.js | 4 ++-- src/ol/geom/LineString.js | 4 ++-- src/ol/geom/LinearRing.js | 4 ++-- src/ol/geom/MultiLineString.js | 4 ++-- src/ol/geom/MultiPoint.js | 4 ++-- src/ol/geom/MultiPolygon.js | 4 ++-- src/ol/geom/Point.js | 4 ++-- src/ol/geom/Polygon.js | 4 ++-- src/ol/geom/flat/deflate.js | 22 ++++++++++------------ test/spec/ol/geom/flat/deflate.test.js | 6 +++--- 11 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/ol/format/EsriJSON.js b/src/ol/format/EsriJSON.js index f2158245c4..f56d27b99d 100644 --- a/src/ol/format/EsriJSON.js +++ b/src/ol/format/EsriJSON.js @@ -16,7 +16,7 @@ import MultiPoint from '../geom/MultiPoint.js'; import MultiPolygon from '../geom/MultiPolygon.js'; import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinates} from '../geom/flat/deflate.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; import {assign, isEmpty} from '../obj.js'; import {get as getProjection} from '../proj.js'; @@ -132,7 +132,7 @@ function convertRings(rings, layout) { let i, ii; for (i = 0, ii = rings.length; i < ii; ++i) { flatRing.length = 0; - _ol_geom_flat_deflate_.coordinates(flatRing, 0, rings[i], layout.length); + deflateCoordinates(flatRing, 0, rings[i], layout.length); // is this ring an outer ring? is it clockwise? const clockwise = _ol_geom_flat_orient_.linearRingIsClockwise(flatRing, 0, flatRing.length, layout.length); diff --git a/src/ol/geom/Circle.js b/src/ol/geom/Circle.js index 9c6de67a51..4a4fd062f1 100644 --- a/src/ol/geom/Circle.js +++ b/src/ol/geom/Circle.js @@ -6,7 +6,7 @@ import {createOrUpdate, forEachCorner, intersects} from '../extent.js'; import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinate} from '../geom/flat/deflate.js'; /** * @classdesc @@ -192,7 +192,7 @@ Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) { } /** @type {Array.} */ const flatCoordinates = this.flatCoordinates; - let offset = _ol_geom_flat_deflate_.coordinate( + let offset = deflateCoordinate( flatCoordinates, 0, center, this.stride); flatCoordinates[offset++] = flatCoordinates[0] + radius; for (let i = 1, ii = this.stride; i < ii; ++i) { diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index da50f9bb0a..16ca750acb 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -8,7 +8,7 @@ import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; @@ -250,7 +250,7 @@ LineString.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - this.flatCoordinates.length = _ol_geom_flat_deflate_.coordinates( + this.flatCoordinates.length = deflateCoordinates( this.flatCoordinates, 0, coordinates, this.stride); this.changed(); } diff --git a/src/ol/geom/LinearRing.js b/src/ol/geom/LinearRing.js index 2acac977df..4346897b42 100644 --- a/src/ol/geom/LinearRing.js +++ b/src/ol/geom/LinearRing.js @@ -8,7 +8,7 @@ import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import {linearRing as linearRingArea} from '../geom/flat/area.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; @@ -144,7 +144,7 @@ LinearRing.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - this.flatCoordinates.length = _ol_geom_flat_deflate_.coordinates( + this.flatCoordinates.length = deflateCoordinates( this.flatCoordinates, 0, coordinates, this.stride); this.changed(); } diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index 1e6e2f4179..de620b2f28 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -9,7 +9,7 @@ import GeometryType from '../geom/GeometryType.js'; import LineString from '../geom/LineString.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; @@ -267,7 +267,7 @@ MultiLineString.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - const ends = _ol_geom_flat_deflate_.coordinatess( + const ends = deflateCoordinatesArray( this.flatCoordinates, 0, coordinates, this.stride, this.ends_); this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1]; this.changed(); diff --git a/src/ol/geom/MultiPoint.js b/src/ol/geom/MultiPoint.js index d5ed8a9ff0..e2b0f9ae5a 100644 --- a/src/ol/geom/MultiPoint.js +++ b/src/ol/geom/MultiPoint.js @@ -8,7 +8,7 @@ import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import Point from '../geom/Point.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; import {squaredDistance as squaredDx} from '../math.js'; @@ -174,7 +174,7 @@ MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - this.flatCoordinates.length = _ol_geom_flat_deflate_.coordinates( + this.flatCoordinates.length = deflateCoordinates( this.flatCoordinates, 0, coordinates, this.stride); this.changed(); } diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index a3b539b748..517e3b9773 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -13,7 +13,7 @@ import {linearRingss as linearRingssArea} from '../geom/flat/area.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {linearRingssContainsXY} from '../geom/flat/contains.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; @@ -364,7 +364,7 @@ MultiPolygon.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - const endss = _ol_geom_flat_deflate_.coordinatesss( + const endss = deflateMultiCoordinatesArray( this.flatCoordinates, 0, coordinates, this.stride, this.endss_); if (endss.length === 0) { this.flatCoordinates.length = 0; diff --git a/src/ol/geom/Point.js b/src/ol/geom/Point.js index 931ac44f69..9d30635bc7 100644 --- a/src/ol/geom/Point.js +++ b/src/ol/geom/Point.js @@ -6,7 +6,7 @@ import {createOrUpdateFromCoordinate, containsXY} from '../extent.js'; import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinate} from '../geom/flat/deflate.js'; import {squaredDistance as squaredDx} from '../math.js'; /** @@ -108,7 +108,7 @@ Point.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - this.flatCoordinates.length = _ol_geom_flat_deflate_.coordinate( + this.flatCoordinates.length = deflateCoordinate( this.flatCoordinates, 0, coordinates, this.stride); this.changed(); } diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 6620dbaf20..c345404903 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -13,7 +13,7 @@ import {offset as sphereOffset} from '../sphere.js'; import {linearRings as linearRingsArea} from '../geom/flat/area.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {linearRingsContainsXY} from '../geom/flat/contains.js'; -import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js'; +import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; @@ -345,7 +345,7 @@ Polygon.prototype.setCoordinates = function(coordinates, opt_layout) { if (!this.flatCoordinates) { this.flatCoordinates = []; } - const ends = _ol_geom_flat_deflate_.coordinatess( + const ends = deflateCoordinatesArray( this.flatCoordinates, 0, coordinates, this.stride, this.ends_); this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1]; this.changed(); diff --git a/src/ol/geom/flat/deflate.js b/src/ol/geom/flat/deflate.js index 71539a5dca..1295c16a71 100644 --- a/src/ol/geom/flat/deflate.js +++ b/src/ol/geom/flat/deflate.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/deflate */ -const _ol_geom_flat_deflate_ = {}; /** @@ -11,12 +10,12 @@ const _ol_geom_flat_deflate_ = {}; * @param {number} stride Stride. * @return {number} offset Offset. */ -_ol_geom_flat_deflate_.coordinate = function(flatCoordinates, offset, coordinate, stride) { +export function deflateCoordinate(flatCoordinates, offset, coordinate, stride) { for (let i = 0, ii = coordinate.length; i < ii; ++i) { flatCoordinates[offset++] = coordinate[i]; } return offset; -}; +} /** @@ -26,7 +25,7 @@ _ol_geom_flat_deflate_.coordinate = function(flatCoordinates, offset, coordinate * @param {number} stride Stride. * @return {number} offset Offset. */ -_ol_geom_flat_deflate_.coordinates = function(flatCoordinates, offset, coordinates, stride) { +export function deflateCoordinates(flatCoordinates, offset, coordinates, stride) { for (let i = 0, ii = coordinates.length; i < ii; ++i) { const coordinate = coordinates[i]; for (let j = 0; j < stride; ++j) { @@ -34,7 +33,7 @@ _ol_geom_flat_deflate_.coordinates = function(flatCoordinates, offset, coordinat } } return offset; -}; +} /** @@ -45,18 +44,18 @@ _ol_geom_flat_deflate_.coordinates = function(flatCoordinates, offset, coordinat * @param {Array.=} opt_ends Ends. * @return {Array.} Ends. */ -_ol_geom_flat_deflate_.coordinatess = function(flatCoordinates, offset, coordinatess, stride, opt_ends) { +export function deflateCoordinatesArray(flatCoordinates, offset, coordinatess, stride, opt_ends) { const ends = opt_ends ? opt_ends : []; let i = 0; for (let j = 0, jj = coordinatess.length; j < jj; ++j) { - const end = _ol_geom_flat_deflate_.coordinates( + const end = deflateCoordinates( flatCoordinates, offset, coordinatess[j], stride); ends[i++] = end; offset = end; } ends.length = i; return ends; -}; +} /** @@ -67,16 +66,15 @@ _ol_geom_flat_deflate_.coordinatess = function(flatCoordinates, offset, coordina * @param {Array.>=} opt_endss Endss. * @return {Array.>} Endss. */ -_ol_geom_flat_deflate_.coordinatesss = function(flatCoordinates, offset, coordinatesss, stride, opt_endss) { +export function deflateMultiCoordinatesArray(flatCoordinates, offset, coordinatesss, stride, opt_endss) { const endss = opt_endss ? opt_endss : []; let i = 0; for (let j = 0, jj = coordinatesss.length; j < jj; ++j) { - const ends = _ol_geom_flat_deflate_.coordinatess( + const ends = deflateCoordinatesArray( flatCoordinates, offset, coordinatesss[j], stride, endss[i]); endss[i++] = ends; offset = ends[ends.length - 1]; } endss.length = i; return endss; -}; -export default _ol_geom_flat_deflate_; +} diff --git a/test/spec/ol/geom/flat/deflate.test.js b/test/spec/ol/geom/flat/deflate.test.js index 1b88ec8638..a7f34e2f91 100644 --- a/test/spec/ol/geom/flat/deflate.test.js +++ b/test/spec/ol/geom/flat/deflate.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_deflate_ from '../../../../../src/ol/geom/flat/deflate.js'; +import {deflateCoordinates, deflateCoordinatesArray} from '../../../../../src/ol/geom/flat/deflate.js'; describe('ol.geom.flat.deflate', function() { @@ -11,7 +11,7 @@ describe('ol.geom.flat.deflate', function() { }); it('flattens coordinates', function() { - const offset = _ol_geom_flat_deflate_.coordinates( + const offset = deflateCoordinates( flatCoordinates, 0, [[1, 2], [3, 4]], 2); expect(offset).to.be(4); expect(flatCoordinates).to.eql([1, 2, 3, 4]); @@ -27,7 +27,7 @@ describe('ol.geom.flat.deflate', function() { }); it('flattens arrays of coordinates', function() { - const ends = _ol_geom_flat_deflate_.coordinatess(flatCoordinates, 0, + const ends = deflateCoordinatesArray(flatCoordinates, 0, [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], 2); expect(ends).to.eql([4, 8]); expect(flatCoordinates).to.eql([1, 2, 3, 4, 5, 6, 7, 8]); From 05a648d4f36485bb0f68029b9cf2099bbc1336b2 Mon Sep 17 00:00:00 2001 From: raiyni Date: Mon, 12 Feb 2018 23:27:38 -0600 Subject: [PATCH 03/13] ol/geom/flat/length export --- src/ol/geom/LineString.js | 4 ++-- src/ol/geom/flat/length.js | 12 +++++------- src/ol/render/canvas/Replay.js | 4 ++-- test/spec/ol/geom/flat/length.test.js | 18 +++++++++--------- test/spec/ol/geom/flat/textpath.test.js | 12 ++++++------ 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 16ca750acb..22117d03fc 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -12,7 +12,7 @@ import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.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_length_ from '../geom/flat/length.js'; +import {lineStringLength} from '../geom/flat/length.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js'; import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; @@ -183,7 +183,7 @@ LineString.prototype.getCoordinateAt = function(fraction, opt_dest) { * @api */ LineString.prototype.getLength = function() { - return _ol_geom_flat_length_.lineString( + return lineStringLength( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride); }; diff --git a/src/ol/geom/flat/length.js b/src/ol/geom/flat/length.js index c1139211a4..3a329da814 100644 --- a/src/ol/geom/flat/length.js +++ b/src/ol/geom/flat/length.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/length */ -const _ol_geom_flat_length_ = {}; /** @@ -11,7 +10,7 @@ const _ol_geom_flat_length_ = {}; * @param {number} stride Stride. * @return {number} Length. */ -_ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride) { +export function lineStringLength(flatCoordinates, offset, end, stride) { let x1 = flatCoordinates[offset]; let y1 = flatCoordinates[offset + 1]; let length = 0; @@ -23,7 +22,7 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride y1 = y2; } return length; -}; +} /** @@ -33,11 +32,10 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride * @param {number} stride Stride. * @return {number} Perimeter. */ -_ol_geom_flat_length_.linearRing = function(flatCoordinates, offset, end, stride) { - let perimeter = _ol_geom_flat_length_.lineString(flatCoordinates, offset, end, stride); +export function linearRingLength(flatCoordinates, offset, end, stride) { + let perimeter = lineStringLength(flatCoordinates, offset, end, stride); const dx = flatCoordinates[end - stride] - flatCoordinates[offset]; const dy = flatCoordinates[end - stride + 1] - flatCoordinates[offset + 1]; perimeter += Math.sqrt(dx * dx + dy * dy); return perimeter; -}; -export default _ol_geom_flat_length_; +} diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index 329815acac..b43195e582 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -9,7 +9,7 @@ import {buffer, clone, coordinateRelationship, createEmpty, createOrUpdate, import Relationship from '../../extent/Relationship.js'; import GeometryType from '../../geom/GeometryType.js'; import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js'; -import _ol_geom_flat_length_ from '../../geom/flat/length.js'; +import {lineStringLength} from '../../geom/flat/length.js'; import _ol_geom_flat_textpath_ from '../../geom/flat/textpath.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import {CANVAS_LINE_DASH} from '../../has.js'; @@ -710,7 +710,7 @@ CanvasReplay.prototype.replay_ = function( const textKey = /** @type {string} */ (instruction[13]); const textScale = /** @type {number} */ (instruction[14]); - const pathLength = _ol_geom_flat_length_.lineString(pixelCoordinates, begin, end, 2); + const pathLength = lineStringLength(pixelCoordinates, begin, end, 2); const textLength = measure(text); if (overflow || textLength <= pathLength) { const textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign; diff --git a/test/spec/ol/geom/flat/length.test.js b/test/spec/ol/geom/flat/length.test.js index 9539557176..030608b545 100644 --- a/test/spec/ol/geom/flat/length.test.js +++ b/test/spec/ol/geom/flat/length.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js'; +import {lineStringLength, linearRingLength} from '../../../../../src/ol/geom/flat/length.js'; describe('ol.geom.flat.length', function() { @@ -13,7 +13,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 8; const expected = 3; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -21,7 +21,7 @@ describe('ol.geom.flat.length', function() { const offset = 2; const end = 8; const expected = 2; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -29,7 +29,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 4; const expected = 1; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -43,7 +43,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 12; const expected = 3; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -51,7 +51,7 @@ describe('ol.geom.flat.length', function() { const offset = 3; const end = 12; const expected = 2; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -59,7 +59,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 6; const expected = 1; - const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride); + const got = lineStringLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -74,7 +74,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 8; const expected = 4; - const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride); + const got = linearRingLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); @@ -84,7 +84,7 @@ describe('ol.geom.flat.length', function() { const offset = 0; const end = 14; const expected = 8; - const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride); + const got = linearRingLength(flatCoords, offset, end, stride); expect(got).to.be(expected); }); diff --git a/test/spec/ol/geom/flat/textpath.test.js b/test/spec/ol/geom/flat/textpath.test.js index dea6fda047..4b63c0bd02 100644 --- a/test/spec/ol/geom/flat/textpath.test.js +++ b/test/spec/ol/geom/flat/textpath.test.js @@ -1,5 +1,5 @@ import _ol_geom_flat_textpath_ from '../../../../../src/ol/geom/flat/textpath.js'; -import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js'; +import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js'; describe('textpath', function() { @@ -67,7 +67,7 @@ describe('textpath', function() { }); it('renders angled text', function() { - const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2); + const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 0, angled.length, 2, 'foo', measure, startM, Infinity); @@ -78,7 +78,7 @@ describe('textpath', function() { }); it('respects maxAngle', function() { - const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2); + const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4); @@ -86,7 +86,7 @@ describe('textpath', function() { }); it('uses the smallest angle for maxAngleDelta', function() { - const length = _ol_geom_flat_length_.lineString(reverseangled, 0, reverseangled.length, 2); + const length = lineStringLength(reverseangled, 0, reverseangled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI); @@ -94,7 +94,7 @@ describe('textpath', function() { }); it('respects the offset option', function() { - const length = _ol_geom_flat_length_.lineString(angled, 2, angled.length, 2); + const length = lineStringLength(angled, 2, angled.length, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 2, angled.length, 2, 'foo', measure, startM, Infinity); @@ -103,7 +103,7 @@ describe('textpath', function() { }); it('respects the end option', function() { - const length = _ol_geom_flat_length_.lineString(angled, 0, 4, 2); + const length = lineStringLength(angled, 0, 4, 2); const startM = length / 2 - 15; const instructions = _ol_geom_flat_textpath_.lineString( angled, 0, 4, 2, 'foo', measure, startM, Infinity); From 2550ab16916523ff58fe486cc69b78e869630299 Mon Sep 17 00:00:00 2001 From: raiyni Date: Mon, 12 Feb 2018 23:34:21 -0600 Subject: [PATCH 04/13] ol/geom/flat/textpath export --- src/ol/geom/flat/textpath.js | 6 ++---- src/ol/render/canvas/Replay.js | 4 ++-- test/spec/ol/geom/flat/textpath.test.js | 26 ++++++++++++------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/ol/geom/flat/textpath.js b/src/ol/geom/flat/textpath.js index d4bb434f9a..5b0d9648c6 100644 --- a/src/ol/geom/flat/textpath.js +++ b/src/ol/geom/flat/textpath.js @@ -2,7 +2,6 @@ * @module ol/geom/flat/textpath */ import {lerp} from '../../math.js'; -const _ol_geom_flat_textpath_ = {}; /** @@ -18,7 +17,7 @@ const _ol_geom_flat_textpath_ = {}; * @return {Array.>} The result array of null if `maxAngle` was * exceeded. Entries of the array are x, y, anchorX, angle, chunk. */ -_ol_geom_flat_textpath_.lineString = function( +export function drawTextOnPath( flatCoordinates, offset, end, stride, text, measure, startM, maxAngle) { const result = []; @@ -90,5 +89,4 @@ _ol_geom_flat_textpath_.lineString = function( startM += charLength; } return result; -}; -export default _ol_geom_flat_textpath_; +} diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index b43195e582..6580f16312 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -10,7 +10,7 @@ import Relationship from '../../extent/Relationship.js'; import GeometryType from '../../geom/GeometryType.js'; import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js'; import {lineStringLength} from '../../geom/flat/length.js'; -import _ol_geom_flat_textpath_ from '../../geom/flat/textpath.js'; +import {drawTextOnPath} from '../../geom/flat/textpath.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import {CANVAS_LINE_DASH} from '../../has.js'; import {isEmpty} from '../../obj.js'; @@ -715,7 +715,7 @@ CanvasReplay.prototype.replay_ = function( if (overflow || textLength <= pathLength) { const textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign; const startM = (pathLength - textLength) * _ol_render_replay_.TEXT_ALIGN[textAlign]; - const parts = _ol_geom_flat_textpath_.lineString( + const parts = drawTextOnPath( pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle); if (parts) { let c, cc, chars, label, part; diff --git a/test/spec/ol/geom/flat/textpath.test.js b/test/spec/ol/geom/flat/textpath.test.js index 4b63c0bd02..302f312b05 100644 --- a/test/spec/ol/geom/flat/textpath.test.js +++ b/test/spec/ol/geom/flat/textpath.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_textpath_ from '../../../../../src/ol/geom/flat/textpath.js'; +import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js'; import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js'; describe('textpath', function() { @@ -16,27 +16,27 @@ describe('textpath', function() { it('center-aligns text on a horizontal line', function() { const startM = 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity); expect(instructions).to.eql([[40, 0, 5, 0, 'foo']]); }); it('left-aligns text on a horizontal line', function() { - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo', measure, 0, Infinity); expect(instructions).to.eql([[5, 0, 5, 0, 'foo']]); }); it('right-aligns text on a horizontal line', function() { const startM = 100 - 30; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity); expect(instructions).to.eql([[75, 0, 5, 0, 'foo']]); }); it('draws text on a vertical line', function() { const startM = 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( vertical, 0, vertical.length, 2, 'foo', measure, startM, Infinity); const a = 90 * Math.PI / 180; expect(instructions).to.eql([[0, 40, 5, a, 'foo']]); @@ -44,7 +44,7 @@ describe('textpath', function() { it('draws text on a diagonal line', function() { const startM = Math.sqrt(2) * 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( diagonal, 0, diagonal.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(45 * Math.PI / 180); expect(instructions.length).to.be(1); @@ -52,7 +52,7 @@ describe('textpath', function() { it('draws reverse text on a diagonal line', function() { const startM = Math.sqrt(2) * 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( reverse, 0, reverse.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(-45 * Math.PI / 180); expect(instructions.length).to.be(1); @@ -60,7 +60,7 @@ describe('textpath', function() { it('renders long text with extrapolation', function() { const startM = 50 - 75; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', measure, startM, Infinity); expect(instructions[0]).to.eql([-20, 0, 5, 0, 'foo-foo-foo-foo']); expect(instructions.length).to.be(1); @@ -69,7 +69,7 @@ describe('textpath', function() { it('renders angled text', function() { const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 0, angled.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.eql(45 * Math.PI / 180); expect(instructions[0][4]).to.be('fo'); @@ -80,7 +80,7 @@ describe('textpath', function() { it('respects maxAngle', function() { const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4); expect(instructions).to.be(null); }); @@ -88,7 +88,7 @@ describe('textpath', function() { it('uses the smallest angle for maxAngleDelta', function() { const length = lineStringLength(reverseangled, 0, reverseangled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI); expect(instructions).to.not.be(undefined); }); @@ -96,7 +96,7 @@ describe('textpath', function() { it('respects the offset option', function() { const length = lineStringLength(angled, 2, angled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 2, angled.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(-45 * Math.PI / 180); expect(instructions.length).to.be(1); @@ -105,7 +105,7 @@ describe('textpath', function() { it('respects the end option', function() { const length = lineStringLength(angled, 0, 4, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 0, 4, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(45 * Math.PI / 180); expect(instructions.length).to.be(1); From 78b418ba9db6ccce54a167fff0d361a4fb4c0ca3 Mon Sep 17 00:00:00 2001 From: raiyni Date: Mon, 12 Feb 2018 23:42:11 -0600 Subject: [PATCH 05/13] ol/geom/flat/straightchunk export --- src/ol/geom/flat/straightchunk.js | 6 ++---- src/ol/render/canvas/TextReplay.js | 4 ++-- test/spec/ol/geom/flat/straightchunk.test.js | 14 +++++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/ol/geom/flat/straightchunk.js b/src/ol/geom/flat/straightchunk.js index 16c77598bc..f394537724 100644 --- a/src/ol/geom/flat/straightchunk.js +++ b/src/ol/geom/flat/straightchunk.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/straightchunk */ -const _ol_geom_flat_straightchunk_ = {}; /** @@ -13,7 +12,7 @@ const _ol_geom_flat_straightchunk_ = {}; * @return {Array.} Start and end of the first suitable chunk of the * given `flatCoordinates`. */ -_ol_geom_flat_straightchunk_.lineString = function(maxAngle, flatCoordinates, offset, end, stride) { +export function matchingChunk(maxAngle, flatCoordinates, offset, end, stride) { let chunkStart = offset; let chunkEnd = offset; let chunkM = 0; @@ -49,5 +48,4 @@ _ol_geom_flat_straightchunk_.lineString = function(maxAngle, flatCoordinates, of } m += m23; return m > chunkM ? [start, i] : [chunkStart, chunkEnd]; -}; -export default _ol_geom_flat_straightchunk_; +} diff --git a/src/ol/render/canvas/TextReplay.js b/src/ol/render/canvas/TextReplay.js index f24b19a6c6..9db0c5305b 100644 --- a/src/ol/render/canvas/TextReplay.js +++ b/src/ol/render/canvas/TextReplay.js @@ -5,7 +5,7 @@ import {getUid, inherits} from '../../index.js'; import {asColorLike} from '../../colorlike.js'; import {createCanvasContext2D} from '../../dom.js'; import {intersects} from '../../extent.js'; -import _ol_geom_flat_straightchunk_ from '../../geom/flat/straightchunk.js'; +import {matchingChunk} from '../../geom/flat/straightchunk.js'; import GeometryType from '../../geom/GeometryType.js'; import {CANVAS_LINE_DASH, SAFARI} from '../../has.js'; import _ol_render_canvas_ from '../canvas.js'; @@ -202,7 +202,7 @@ CanvasTextReplay.prototype.drawText = function(geometry, feature) { let flatEnd; for (let o = 0, oo = ends.length; o < oo; ++o) { if (textAlign == undefined) { - const range = _ol_geom_flat_straightchunk_.lineString( + const range = matchingChunk( textState.maxAngle, flatCoordinates, flatOffset, ends[o], stride); flatOffset = range[0]; flatEnd = range[1]; diff --git a/test/spec/ol/geom/flat/straightchunk.test.js b/test/spec/ol/geom/flat/straightchunk.test.js index 087ebf6a2b..7b58017117 100644 --- a/test/spec/ol/geom/flat/straightchunk.test.js +++ b/test/spec/ol/geom/flat/straightchunk.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_straightchunk_ from '../../../../../src/ol/geom/flat/straightchunk.js'; +import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js'; describe('ol.geom.flat.straightchunk', function() { @@ -10,12 +10,12 @@ describe('ol.geom.flat.straightchunk', function() { const stride = 3; it('returns whole line with angle delta', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 6, stride); + const got = matchingChunk(Math.PI / 4, flatCoords, 0, 6, stride); expect(got).to.eql([0, 6]); }); it('returns whole line with zero angle delta', function() { - const got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 6, stride); + const got = matchingChunk(0, flatCoords, 0, 6, stride); expect(got).to.eql([0, 6]); }); @@ -26,12 +26,12 @@ describe('ol.geom.flat.straightchunk', function() { const stride = 2; it('returns whole line if straight enough', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI, flatCoords, 0, 8, stride); + const got = matchingChunk(Math.PI, flatCoords, 0, 8, stride); expect(got).to.eql([0, 8]); }); it('returns first matching chunk if all chunk lengths are the same', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 8, stride); + const got = matchingChunk(Math.PI / 4, flatCoords, 0, 8, stride); expect(got).to.eql([0, 4]); }); @@ -42,12 +42,12 @@ describe('ol.geom.flat.straightchunk', function() { const stride = 2; it('returns stright chunk from within the linestring', function() { - const got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 18, stride); + const got = matchingChunk(0, flatCoords, 0, 18, stride); expect(got).to.eql([10, 16]); }); it('returns long chunk at the end if angle and length within threshold', function() { - const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 18, stride); + const got = matchingChunk(Math.PI / 4, flatCoords, 0, 18, stride); expect(got).to.eql([10, 18]); }); From 837490b4a466495c9af8ba3cfe8093e32893e119 Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 00:08:20 -0600 Subject: [PATCH 06/13] ol/geom/flat/simplify export --- src/ol/geom/LineString.js | 4 +- src/ol/geom/LinearRing.js | 4 +- src/ol/geom/MultiLineString.js | 4 +- src/ol/geom/MultiPolygon.js | 4 +- src/ol/geom/Polygon.js | 4 +- src/ol/geom/flat/simplify.js | 62 +++++++++---------- src/ol/render/canvas/PolygonReplay.js | 4 +- test/spec/ol/geom/flat/simplify.test.js | 82 ++++++++++++------------- 8 files changed, 83 insertions(+), 85 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 22117d03fc..2b41259834 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -14,7 +14,7 @@ import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import {lineStringLength} from '../geom/flat/length.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {douglasPeucker} from '../geom/flat/simplify.js'; /** * @classdesc @@ -205,7 +205,7 @@ LineString.prototype.getFlatMidpoint = function() { */ LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedFlatCoordinates.length = douglasPeucker( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0); const simplifiedLineString = new LineString(null); diff --git a/src/ol/geom/LinearRing.js b/src/ol/geom/LinearRing.js index 4346897b42..e80193eae8 100644 --- a/src/ol/geom/LinearRing.js +++ b/src/ol/geom/LinearRing.js @@ -10,7 +10,7 @@ import {linearRing as linearRingArea} from '../geom/flat/area.js'; import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {douglasPeucker} from '../geom/flat/simplify.js'; /** * @classdesc @@ -104,7 +104,7 @@ LinearRing.prototype.getCoordinates = function() { */ LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedFlatCoordinates.length = douglasPeucker( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0); const simplifiedLinearRing = new LinearRing(null); diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index de620b2f28..fb72c107fb 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -13,7 +13,7 @@ import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.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_simplify_ from '../geom/flat/simplify.js'; +import {douglasPeuckerArray} from '../geom/flat/simplify.js'; /** * @classdesc @@ -223,7 +223,7 @@ MultiLineString.prototype.getFlatMidpoints = function() { MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; const simplifiedEnds = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeuckers( + simplifiedFlatCoordinates.length = douglasPeuckerArray( this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance, simplifiedFlatCoordinates, 0, simplifiedEnds); const simplifiedMultiLineString = new MultiLineString(null); diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 517e3b9773..5fe7cd98e6 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -18,7 +18,7 @@ import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {quantizeMultiArray} from '../geom/flat/simplify.js'; /** * @classdesc @@ -259,7 +259,7 @@ MultiPolygon.prototype.getOrientedFlatCoordinates = function() { MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; const simplifiedEndss = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.quantizess( + simplifiedFlatCoordinates.length = quantizeMultiArray( this.flatCoordinates, 0, this.endss_, this.stride, Math.sqrt(squaredTolerance), simplifiedFlatCoordinates, 0, simplifiedEndss); diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index c345404903..55841b9ead 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -18,7 +18,7 @@ import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; -import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js'; +import {quantizeArray} from '../geom/flat/simplify.js'; import {modulo} from '../math.js'; /** @@ -300,7 +300,7 @@ Polygon.prototype.getOrientedFlatCoordinates = function() { Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) { const simplifiedFlatCoordinates = []; const simplifiedEnds = []; - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.quantizes( + simplifiedFlatCoordinates.length = quantizeArray( this.flatCoordinates, 0, this.ends_, this.stride, Math.sqrt(squaredTolerance), simplifiedFlatCoordinates, 0, simplifiedEnds); diff --git a/src/ol/geom/flat/simplify.js b/src/ol/geom/flat/simplify.js index a9928896a3..393a8a362b 100644 --- a/src/ol/geom/flat/simplify.js +++ b/src/ol/geom/flat/simplify.js @@ -28,7 +28,6 @@ // POSSIBILITY OF SUCH DAMAGE. import {squaredSegmentDistance, squaredDistance} from '../../math.js'; -const _ol_geom_flat_simplify_ = {}; /** @@ -42,23 +41,23 @@ const _ol_geom_flat_simplify_ = {}; * coordinates. * @return {Array.} Simplified line string. */ -_ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end, +export function simplifyLineString(flatCoordinates, offset, end, stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) { const simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ? opt_simplifiedFlatCoordinates : []; if (!highQuality) { - end = _ol_geom_flat_simplify_.radialDistance(flatCoordinates, offset, end, + end = radialDistance(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, 0); flatCoordinates = simplifiedFlatCoordinates; offset = 0; stride = 2; } - simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedFlatCoordinates.length = douglasPeucker( flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, 0); return simplifiedFlatCoordinates; -}; +} /** @@ -72,7 +71,7 @@ _ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end, * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end, +export function douglasPeucker(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) { const n = (end - offset) / stride; if (n < 3) { @@ -128,7 +127,7 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end, } } return simplifiedOffset; -}; +} /** @@ -143,19 +142,19 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end, * @param {Array.} simplifiedEnds Simplified ends. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset, +export function douglasPeuckerArray(flatCoordinates, offset, ends, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) { for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - simplifiedOffset = _ol_geom_flat_simplify_.douglasPeucker( + simplifiedOffset = douglasPeucker( flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset); simplifiedEnds.push(simplifiedOffset); offset = end; } return simplifiedOffset; -}; +} /** @@ -170,20 +169,20 @@ _ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset, * @param {Array.>} simplifiedEndss Simplified endss. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.douglasPeuckerss = function( +export function douglasPeuckerMultiArray( flatCoordinates, offset, endss, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) { for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; const simplifiedEnds = []; - simplifiedOffset = _ol_geom_flat_simplify_.douglasPeuckers( + simplifiedOffset = douglasPeuckerArray( flatCoordinates, offset, ends, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds); simplifiedEndss.push(simplifiedEnds); offset = ends[ends.length - 1]; } return simplifiedOffset; -}; +} /** @@ -197,7 +196,7 @@ _ol_geom_flat_simplify_.douglasPeuckerss = function( * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end, +export function radialDistance(flatCoordinates, offset, end, stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) { if (end <= offset + stride) { // zero or one point, no simplification possible, so copy and return @@ -232,7 +231,7 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end, simplifiedFlatCoordinates[simplifiedOffset++] = y2; } return simplifiedOffset; -}; +} /** @@ -240,9 +239,9 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end, * @param {number} tolerance Tolerance. * @return {number} Rounded value. */ -_ol_geom_flat_simplify_.snap = function(value, tolerance) { +export function snap(value, tolerance) { return tolerance * Math.round(value / tolerance); -}; +} /** @@ -264,15 +263,15 @@ _ol_geom_flat_simplify_.snap = function(value, tolerance) { * @param {number} simplifiedOffset Simplified offset. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride, +export function quantize(flatCoordinates, offset, end, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset) { // do nothing if the line is empty if (offset == end) { return simplifiedOffset; } // snap the first coordinate (P1) - let x1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance); - let y1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance); + let x1 = snap(flatCoordinates[offset], tolerance); + let y1 = snap(flatCoordinates[offset + 1], tolerance); offset += stride; // add the first coordinate to the output simplifiedFlatCoordinates[simplifiedOffset++] = x1; @@ -281,8 +280,8 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride // coordinate (P2) let x2, y2; do { - x2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance); - y2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance); + x2 = snap(flatCoordinates[offset], tolerance); + y2 = snap(flatCoordinates[offset + 1], tolerance); offset += stride; if (offset == end) { // all coordinates snap to the same value, the line collapses to a point @@ -296,8 +295,8 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride } while (x2 == x1 && y2 == y1); while (offset < end) { // snap the next coordinate (P3) - const x3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance); - const y3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance); + const x3 = snap(flatCoordinates[offset], tolerance); + const y3 = snap(flatCoordinates[offset + 1], tolerance); offset += stride; // skip P3 if it is equal to P2 if (x3 == x2 && y3 == y2) { @@ -334,7 +333,7 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride simplifiedFlatCoordinates[simplifiedOffset++] = x2; simplifiedFlatCoordinates[simplifiedOffset++] = y2; return simplifiedOffset; -}; +} /** @@ -349,13 +348,13 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride * @param {Array.} simplifiedEnds Simplified ends. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.quantizes = function( +export function quantizeArray( flatCoordinates, offset, ends, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) { for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - simplifiedOffset = _ol_geom_flat_simplify_.quantize( + simplifiedOffset = quantize( flatCoordinates, offset, end, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset); @@ -363,7 +362,7 @@ _ol_geom_flat_simplify_.quantizes = function( offset = end; } return simplifiedOffset; -}; +} /** @@ -378,14 +377,14 @@ _ol_geom_flat_simplify_.quantizes = function( * @param {Array.>} simplifiedEndss Simplified endss. * @return {number} Simplified offset. */ -_ol_geom_flat_simplify_.quantizess = function( +export function quantizeMultiArray( flatCoordinates, offset, endss, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) { for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; const simplifiedEnds = []; - simplifiedOffset = _ol_geom_flat_simplify_.quantizes( + simplifiedOffset = quantizeArray( flatCoordinates, offset, ends, stride, tolerance, simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds); @@ -393,5 +392,4 @@ _ol_geom_flat_simplify_.quantizess = function( offset = ends[ends.length - 1]; } return simplifiedOffset; -}; -export default _ol_geom_flat_simplify_; +} diff --git a/src/ol/render/canvas/PolygonReplay.js b/src/ol/render/canvas/PolygonReplay.js index 07328c96fb..8b4f403f8e 100644 --- a/src/ol/render/canvas/PolygonReplay.js +++ b/src/ol/render/canvas/PolygonReplay.js @@ -3,7 +3,7 @@ */ import {inherits} from '../../index.js'; import {asString} from '../../color.js'; -import _ol_geom_flat_simplify_ from '../../geom/flat/simplify.js'; +import {snap} from '../../geom/flat/simplify.js'; import _ol_render_canvas_ from '../canvas.js'; import CanvasInstruction from '../canvas/Instruction.js'; import CanvasReplay from '../canvas/Replay.js'; @@ -199,7 +199,7 @@ CanvasPolygonReplay.prototype.finish = function() { if (tolerance !== 0) { const coordinates = this.coordinates; for (let i = 0, ii = coordinates.length; i < ii; ++i) { - coordinates[i] = _ol_geom_flat_simplify_.snap(coordinates[i], tolerance); + coordinates[i] = snap(coordinates[i], tolerance); } } }; diff --git a/test/spec/ol/geom/flat/simplify.test.js b/test/spec/ol/geom/flat/simplify.test.js index 69eb49dbb7..2e3caec2e0 100644 --- a/test/spec/ol/geom/flat/simplify.test.js +++ b/test/spec/ol/geom/flat/simplify.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_simplify_ from '../../../../../src/ol/geom/flat/simplify.js'; +import {douglasPeucker, quantize, radialDistance, simplifyLineString} from '../../../../../src/ol/geom/flat/simplify.js'; describe('ol.geom.flat.simplify', function() { @@ -81,31 +81,31 @@ describe('ol.geom.flat.simplify', function() { 866.36, 480.77 ]; - describe('ol.geom.flat.simplify.lineString', function() { + describe('ol.geom.flat.simplify.simplifyLineString', function() { it('works with empty line strings', function() { - expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, true)).to. + expect(simplifyLineString([], 0, 0, 2, 1, true)).to. eql([]); - expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, false)).to. + expect(simplifyLineString([], 0, 0, 2, 1, false)).to. eql([]); }); it('works with a line string with a single point', function() { - expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, true)).to. + expect(simplifyLineString([1, 2], 0, 2, 2, 1, true)).to. eql([1, 2]); - expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, false)).to. + expect(simplifyLineString([1, 2], 0, 2, 2, 1, false)).to. eql([1, 2]); }); it('returns the expected result with low quality', function() { - const result = _ol_geom_flat_simplify_.lineString( + const result = simplifyLineString( flatCoordinates, 0, flatCoordinates.length, 2, 25, false); expect(result.length).to.be(simplifiedFlatCoordinates.length); expect(result).to.eql(simplifiedFlatCoordinates); }); it('returns the expected result with high quality', function() { - const result = _ol_geom_flat_simplify_.lineString( + const result = simplifyLineString( flatCoordinates, 0, flatCoordinates.length, 2, 25, true); expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length); expect(result).to.eql(simplifiedHighQualityFlatCoordinates); @@ -121,63 +121,63 @@ describe('ol.geom.flat.simplify', function() { }); it('works with empty line strings', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [], 0, 0, 2, 1, dest, 0)).to.be(0); expect(dest).to.eql([]); }); it('works with a line string with a single point', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [1, 2], 0, 2, 2, 1, dest, 0)).to.be(2); expect(dest).to.eql([1, 2]); }); it('works with a line string with two points', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([1, 2, 3, 4]); }); it('works when the points are widely spaced', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8); expect(dest).to.eql([0, 0, 1, 0, 2, 0, 3, 0]); }); it('works when the spacing matches the tolerance', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(6); expect(dest).to.eql([0, 0, 2, 0, 3, 0]); }); it('works when the points are closely spaced', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(6); expect(dest).to.eql([0, 0, 2, 0, 3, 0]); }); it('works when the line oscillates with widely spaced points', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)). to.be(12); expect(dest).to.eql([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); }); it('works when the line oscillates with closely spaced points', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 1, 1]); }); it('works when the line oscillates within the tolerance', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)). to.be(2); expect(dest).to.eql([0, 0]); }); it('works with real data', function() { - expect(_ol_geom_flat_simplify_.radialDistance( + expect(radialDistance( flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)). to.be(simplifiedRadiallyFlatCoordinates.length); expect(dest).to.eql(simplifiedRadiallyFlatCoordinates); @@ -193,93 +193,93 @@ describe('ol.geom.flat.simplify', function() { }); it('works with empty line strings', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [], 0, 0, 2, 1, dest, 0)).to.be(0); expect(dest).to.eql([]); }); it('works with a line string with a single point', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [1, 2], 0, 2, 2, 1, dest, 0)).to.be(2); expect(dest).to.eql([1, 2]); }); it('works with a line string with two points', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([1, 2, 3, 4]); }); it('works when the points are widely spaced', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 3, 0]); }); it('works when the spacing matches the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 3, 0]); }); it('works when the points are closely spaced', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 3, 0]); }); it('does not elimnate points outside the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(6); expect(dest).to.eql([0, 0, 1, 1, 2, 0]); }); it('does eliminate points within the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 2, 0]); }); it('does not eliminate multiple points outside the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8); expect(dest).to.eql([0, 0, 1, 1, 1, -1, 2, 0]); }); it('does eliminate multiple points within the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 2, 0]); }); it('works when the line oscillates with widely spaced points', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).to.be(4); expect(dest).to.eql([0, 0, 1, 1]); }); it('works when the line oscillates with closely spaced points', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)). to.be(4); expect(dest).to.eql([0, 0, 1, 1]); }); it('works when the line oscillates within the tolerance', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)). to.be(4); expect(dest).to.eql([0, 0, 0, 0]); }); it('works on small triangles', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( [3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)).to.be(6); expect(dest).to.eql([3, 0, 5, 2, 5, 0]); }); it('is the same as high quality simplification', function() { - expect(_ol_geom_flat_simplify_.douglasPeucker( + expect(douglasPeucker( flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)). to.be(simplifiedHighQualityFlatCoordinates.length); expect(dest).to.eql(simplifiedHighQualityFlatCoordinates); @@ -291,28 +291,28 @@ describe('ol.geom.flat.simplify', function() { it('handles empty coordinates', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0); expect(simplifiedFlatCoordinates).to.be.empty(); }); it('expands points to a zero-length line', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]); }); it('snaps near-by points to the same value', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]); }); it('eliminates duplicate snapped points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1], 0, 12, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0]); @@ -320,7 +320,7 @@ describe('ol.geom.flat.simplify', function() { it('eliminates horizontal colinear points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 2, 0, 4, 0, 6, 0], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, 0]); @@ -328,7 +328,7 @@ describe('ol.geom.flat.simplify', function() { it('eliminates vertical colinear points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 0, -2, 0, -4, 0, -6], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, -6]); @@ -336,7 +336,7 @@ describe('ol.geom.flat.simplify', function() { it('eliminates diagonal colinear points', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 2, -2, 4, -4, 6, -6], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4); expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, -6]); @@ -344,7 +344,7 @@ describe('ol.geom.flat.simplify', function() { it('handles switchbacks', function() { const simplifiedFlatCoordinates = []; - expect(_ol_geom_flat_simplify_.quantize( + expect(quantize( [0, 0, 2, 0, 0, 0, 4, 0], 0, 8, 2, 2, simplifiedFlatCoordinates, 0)).to.be(8); expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0, 0, 0, 4, 0]); From 45755692388a6dc557ed9ce7f0012d2bacc46f7b Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 08:11:05 -0600 Subject: [PATCH 07/13] ol/geom/flat/interiorpoint export --- src/ol/geom/MultiPolygon.js | 4 ++-- src/ol/geom/Polygon.js | 4 ++-- src/ol/geom/flat/interiorpoint.js | 12 +++++------- src/ol/render/Feature.js | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 5fe7cd98e6..e395b8ece7 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -15,7 +15,7 @@ import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {linearRingssContainsXY} from '../geom/flat/contains.js'; import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; -import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; +import {getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; import {quantizeMultiArray} from '../geom/flat/simplify.js'; @@ -209,7 +209,7 @@ MultiPolygon.prototype.getFlatInteriorPoints = function() { if (this.flatInteriorPointsRevision_ != this.getRevision()) { const flatCenters = linearRingssCenter( this.flatCoordinates, 0, this.endss_, this.stride); - this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRingss( + this.flatInteriorPoints_ = getInteriorPointsOfMultiArray( this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, flatCenters); this.flatInteriorPointsRevision_ = this.getRevision(); diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 55841b9ead..69a51017f1 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -15,7 +15,7 @@ import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; import {linearRingsContainsXY} from '../geom/flat/contains.js'; import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; -import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; +import {getInteriorPointOfArray} from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; import {quantizeArray} from '../geom/flat/simplify.js'; @@ -198,7 +198,7 @@ Polygon.prototype.getEnds = function() { Polygon.prototype.getFlatInteriorPoint = function() { if (this.flatInteriorPointRevision_ != this.getRevision()) { const flatCenter = getCenter(this.getExtent()); - this.flatInteriorPoint_ = _ol_geom_flat_interiorpoint_.linearRings( + this.flatInteriorPoint_ = getInteriorPointOfArray( this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, flatCenter, 0); this.flatInteriorPointRevision_ = this.getRevision(); diff --git a/src/ol/geom/flat/interiorpoint.js b/src/ol/geom/flat/interiorpoint.js index 8045d4980a..98f4d56659 100644 --- a/src/ol/geom/flat/interiorpoint.js +++ b/src/ol/geom/flat/interiorpoint.js @@ -3,7 +3,6 @@ */ import {numberSafeCompareFunction} from '../../array.js'; import {linearRingsContainsXY} from '../flat/contains.js'; -const _ol_geom_flat_interiorpoint_ = {}; /** @@ -19,7 +18,7 @@ const _ol_geom_flat_interiorpoint_ = {}; * @return {Array.} Destination point as XYM coordinate, where M is the * length of the horizontal intersection that the point belongs to. */ -_ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset, +export function getInteriorPointOfArray(flatCoordinates, offset, ends, stride, flatCenters, flatCentersOffset, opt_dest) { let i, ii, x, x1, x2, y1, y2; const y = flatCenters[flatCentersOffset + 1]; @@ -70,7 +69,7 @@ _ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset, } else { return [pointX, y, maxSegmentLength]; } -}; +} /** @@ -82,14 +81,13 @@ _ol_geom_flat_interiorpoint_.linearRings = function(flatCoordinates, offset, * @return {Array.} Interior points as XYM coordinates, where M is the * length of the horizontal intersection that the point belongs to. */ -_ol_geom_flat_interiorpoint_.linearRingss = function(flatCoordinates, offset, endss, stride, flatCenters) { +export function getInteriorPointsOfMultiArray(flatCoordinates, offset, endss, stride, flatCenters) { let interiorPoints = []; for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; - interiorPoints = _ol_geom_flat_interiorpoint_.linearRings(flatCoordinates, + interiorPoints = getInteriorPointOfArray(flatCoordinates, offset, ends, stride, flatCenters, 2 * i, interiorPoints); offset = ends[ends.length - 1]; } return interiorPoints; -}; -export default _ol_geom_flat_interiorpoint_; +} diff --git a/src/ol/render/Feature.js b/src/ol/render/Feature.js index 369c65442c..f72aa7c40f 100644 --- a/src/ol/render/Feature.js +++ b/src/ol/render/Feature.js @@ -6,7 +6,7 @@ import {extend} from '../array.js'; import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCenter, getHeight} from '../extent.js'; import GeometryType from '../geom/GeometryType.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; -import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js'; +import {getInteriorPointOfArray, getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; import _ol_transform_ from '../transform.js'; @@ -125,7 +125,7 @@ RenderFeature.prototype.getExtent = function() { RenderFeature.prototype.getFlatInteriorPoint = function() { if (!this.flatInteriorPoints_) { const flatCenter = getCenter(this.getExtent()); - this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRings( + this.flatInteriorPoints_ = getInteriorPointOfArray( this.flatCoordinates_, 0, this.ends_, 2, flatCenter, 0); } return this.flatInteriorPoints_; @@ -139,7 +139,7 @@ RenderFeature.prototype.getFlatInteriorPoints = function() { if (!this.flatInteriorPoints_) { const flatCenters = linearRingssCenter( this.flatCoordinates_, 0, this.ends_, 2); - this.flatInteriorPoints_ = _ol_geom_flat_interiorpoint_.linearRingss( + this.flatInteriorPoints_ = getInteriorPointsOfMultiArray( this.flatCoordinates_, 0, this.ends_, 2, flatCenters); } return this.flatInteriorPoints_; From 9fc09db89c0e4d91cb325e7180f9cb09bfe6778d Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 08:44:09 -0600 Subject: [PATCH 08/13] ol/geom/flat/closest export --- src/ol/geom/LineString.js | 6 +-- src/ol/geom/LinearRing.js | 6 +-- src/ol/geom/MultiLineString.js | 6 +-- src/ol/geom/MultiPolygon.js | 6 +-- src/ol/geom/Polygon.js | 6 +-- src/ol/geom/flat/closest.js | 62 +++++++++++++------------- test/spec/ol/geom/flat/closest.test.js | 28 ++++++------ 7 files changed, 59 insertions(+), 61 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 2b41259834..beb3d7a8df 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -7,7 +7,7 @@ import {closestSquaredDistanceXY} from '../extent.js'; import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; -import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; +import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; @@ -97,11 +97,11 @@ LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis return minSquaredDistance; } if (this.maxDeltaRevision_ != this.getRevision()) { - this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta( + this.maxDelta_ = Math.sqrt(maxSquaredDelta( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); this.maxDeltaRevision_ = this.getRevision(); } - return _ol_geom_flat_closest_.getClosestPoint( + return assignClosestPoint( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, this.maxDelta_, false, x, y, closestPoint, minSquaredDistance); }; diff --git a/src/ol/geom/LinearRing.js b/src/ol/geom/LinearRing.js index e80193eae8..00c2b8911f 100644 --- a/src/ol/geom/LinearRing.js +++ b/src/ol/geom/LinearRing.js @@ -7,7 +7,7 @@ import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import {linearRing as linearRingArea} from '../geom/flat/area.js'; -import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; +import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; import {douglasPeucker} from '../geom/flat/simplify.js'; @@ -67,11 +67,11 @@ LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis return minSquaredDistance; } if (this.maxDeltaRevision_ != this.getRevision()) { - this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta( + this.maxDelta_ = Math.sqrt(maxSquaredDelta( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); this.maxDeltaRevision_ = this.getRevision(); } - return _ol_geom_flat_closest_.getClosestPoint( + return assignClosestPoint( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, this.maxDelta_, true, x, y, closestPoint, minSquaredDistance); }; diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index fb72c107fb..7d4e8d1106 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -8,7 +8,7 @@ import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import LineString from '../geom/LineString.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; -import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; +import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; @@ -92,11 +92,11 @@ MultiLineString.prototype.closestPointXY = function(x, y, closestPoint, minSquar return minSquaredDistance; } if (this.maxDeltaRevision_ != this.getRevision()) { - this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getsMaxSquaredDelta( + this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta( this.flatCoordinates, 0, this.ends_, this.stride, 0)); this.maxDeltaRevision_ = this.getRevision(); } - return _ol_geom_flat_closest_.getsClosestPoint( + return assignClosestArrayPoint( this.flatCoordinates, 0, this.ends_, this.stride, this.maxDelta_, false, x, y, closestPoint, minSquaredDistance); }; diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index e395b8ece7..9ee2af7e72 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -11,7 +11,7 @@ import Polygon from '../geom/Polygon.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import {linearRingss as linearRingssArea} from '../geom/flat/area.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; -import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; +import {assignClosestMultiArrayPoint, multiArrayMaxSquaredDelta} from '../geom/flat/closest.js'; import {linearRingssContainsXY} from '../geom/flat/contains.js'; import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; @@ -137,11 +137,11 @@ MultiPolygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredD return minSquaredDistance; } if (this.maxDeltaRevision_ != this.getRevision()) { - this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getssMaxSquaredDelta( + this.maxDelta_ = Math.sqrt(multiArrayMaxSquaredDelta( this.flatCoordinates, 0, this.endss_, this.stride, 0)); this.maxDeltaRevision_ = this.getRevision(); } - return _ol_geom_flat_closest_.getssClosestPoint( + return assignClosestMultiArrayPoint( this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, this.maxDelta_, true, x, y, closestPoint, minSquaredDistance); }; diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 69a51017f1..c2ac483f4e 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -11,7 +11,7 @@ import Point from '../geom/Point.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; import {offset as sphereOffset} from '../sphere.js'; import {linearRings as linearRingsArea} from '../geom/flat/area.js'; -import _ol_geom_flat_closest_ from '../geom/flat/closest.js'; +import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js'; import {linearRingsContainsXY} from '../geom/flat/contains.js'; import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; @@ -127,11 +127,11 @@ Polygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistan return minSquaredDistance; } if (this.maxDeltaRevision_ != this.getRevision()) { - this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getsMaxSquaredDelta( + this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta( this.flatCoordinates, 0, this.ends_, this.stride, 0)); this.maxDeltaRevision_ = this.getRevision(); } - return _ol_geom_flat_closest_.getsClosestPoint( + return assignClosestArrayPoint( this.flatCoordinates, 0, this.ends_, this.stride, this.maxDelta_, true, x, y, closestPoint, minSquaredDistance); }; diff --git a/src/ol/geom/flat/closest.js b/src/ol/geom/flat/closest.js index 12d5802592..878944777f 100644 --- a/src/ol/geom/flat/closest.js +++ b/src/ol/geom/flat/closest.js @@ -2,7 +2,6 @@ * @module ol/geom/flat/closest */ import {lerp, squaredDistance as squaredDx} from '../../math.js'; -const _ol_geom_flat_closest_ = {}; /** @@ -17,7 +16,7 @@ const _ol_geom_flat_closest_ = {}; * @param {number} y Y. * @param {Array.} closestPoint Closest point. */ -_ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) { +function assignClosest(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) { const x1 = flatCoordinates[offset1]; const y1 = flatCoordinates[offset1 + 1]; const dx = flatCoordinates[offset2] - x1; @@ -44,7 +43,7 @@ _ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, strid closestPoint[i] = flatCoordinates[offset + i]; } closestPoint.length = stride; -}; +} /** @@ -54,24 +53,24 @@ _ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, strid * @param {number} offset Offset. * @param {number} end End. * @param {number} stride Stride. - * @param {number} maxSquaredDelta Max squared delta. + * @param {number} max Max squared delta. * @return {number} Max squared delta. */ -_ol_geom_flat_closest_.getMaxSquaredDelta = function(flatCoordinates, offset, end, stride, maxSquaredDelta) { +export function maxSquaredDelta(flatCoordinates, offset, end, stride, max) { let x1 = flatCoordinates[offset]; let y1 = flatCoordinates[offset + 1]; for (offset += stride; offset < end; offset += stride) { const x2 = flatCoordinates[offset]; const y2 = flatCoordinates[offset + 1]; const squaredDelta = squaredDx(x1, y1, x2, y2); - if (squaredDelta > maxSquaredDelta) { - maxSquaredDelta = squaredDelta; + if (squaredDelta > max) { + max = squaredDelta; } x1 = x2; y1 = y2; } - return maxSquaredDelta; -}; + return max; +} /** @@ -79,18 +78,18 @@ _ol_geom_flat_closest_.getMaxSquaredDelta = function(flatCoordinates, offset, en * @param {number} offset Offset. * @param {Array.} ends Ends. * @param {number} stride Stride. - * @param {number} maxSquaredDelta Max squared delta. + * @param {number} max Max squared delta. * @return {number} Max squared delta. */ -_ol_geom_flat_closest_.getsMaxSquaredDelta = function(flatCoordinates, offset, ends, stride, maxSquaredDelta) { +export function arrayMaxSquaredDelta(flatCoordinates, offset, ends, stride, max) { for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - maxSquaredDelta = _ol_geom_flat_closest_.getMaxSquaredDelta( - flatCoordinates, offset, end, stride, maxSquaredDelta); + max = maxSquaredDelta( + flatCoordinates, offset, end, stride, max); offset = end; } - return maxSquaredDelta; -}; + return max; +} /** @@ -98,18 +97,18 @@ _ol_geom_flat_closest_.getsMaxSquaredDelta = function(flatCoordinates, offset, e * @param {number} offset Offset. * @param {Array.>} endss Endss. * @param {number} stride Stride. - * @param {number} maxSquaredDelta Max squared delta. + * @param {number} max Max squared delta. * @return {number} Max squared delta. */ -_ol_geom_flat_closest_.getssMaxSquaredDelta = function(flatCoordinates, offset, endss, stride, maxSquaredDelta) { +export function multiArrayMaxSquaredDelta(flatCoordinates, offset, endss, stride, max) { for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; - maxSquaredDelta = _ol_geom_flat_closest_.getsMaxSquaredDelta( - flatCoordinates, offset, ends, stride, maxSquaredDelta); + max = arrayMaxSquaredDelta( + flatCoordinates, offset, ends, stride, max); offset = ends[ends.length - 1]; } - return maxSquaredDelta; -}; + return max; +} /** @@ -126,7 +125,7 @@ _ol_geom_flat_closest_.getssMaxSquaredDelta = function(flatCoordinates, offset, * @param {Array.=} opt_tmpPoint Temporary point object. * @return {number} Minimum squared distance. */ -_ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end, +export function assignClosestPoint(flatCoordinates, offset, end, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance, opt_tmpPoint) { if (offset == end) { @@ -150,7 +149,7 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end, const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN]; let index = offset + stride; while (index < end) { - _ol_geom_flat_closest_.point( + assignClosest( flatCoordinates, index - stride, index, stride, x, y, tmpPoint); squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]); if (squaredDistance < minSquaredDistance) { @@ -178,7 +177,7 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end, } if (isRing) { // Check the closing segment. - _ol_geom_flat_closest_.point( + assignClosest( flatCoordinates, end - stride, offset, stride, x, y, tmpPoint); squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]); if (squaredDistance < minSquaredDistance) { @@ -190,7 +189,7 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end, } } return minSquaredDistance; -}; +} /** @@ -207,19 +206,19 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end, * @param {Array.=} opt_tmpPoint Temporary point object. * @return {number} Minimum squared distance. */ -_ol_geom_flat_closest_.getsClosestPoint = function(flatCoordinates, offset, ends, +export function assignClosestArrayPoint(flatCoordinates, offset, ends, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance, opt_tmpPoint) { const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN]; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - minSquaredDistance = _ol_geom_flat_closest_.getClosestPoint( + minSquaredDistance = assignClosestPoint( flatCoordinates, offset, end, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint); offset = end; } return minSquaredDistance; -}; +} /** @@ -236,17 +235,16 @@ _ol_geom_flat_closest_.getsClosestPoint = function(flatCoordinates, offset, ends * @param {Array.=} opt_tmpPoint Temporary point object. * @return {number} Minimum squared distance. */ -_ol_geom_flat_closest_.getssClosestPoint = function(flatCoordinates, offset, +export function assignClosestMultiArrayPoint(flatCoordinates, offset, endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance, opt_tmpPoint) { const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN]; for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; - minSquaredDistance = _ol_geom_flat_closest_.getsClosestPoint( + minSquaredDistance = assignClosestArrayPoint( flatCoordinates, offset, ends, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint); offset = ends[ends.length - 1]; } return minSquaredDistance; -}; -export default _ol_geom_flat_closest_; +} diff --git a/test/spec/ol/geom/flat/closest.test.js b/test/spec/ol/geom/flat/closest.test.js index 98d0ee94ac..b35b62bd2f 100644 --- a/test/spec/ol/geom/flat/closest.test.js +++ b/test/spec/ol/geom/flat/closest.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_closest_ from '../../../../../src/ol/geom/flat/closest.js'; +import {assignClosestPoint, maxSquaredDelta} from '../../../../../src/ol/geom/flat/closest.js'; describe('ol.geom.flat.closest', function() { @@ -10,7 +10,7 @@ describe('ol.geom.flat.closest', function() { describe('ol.geom.flat.closest.getMaxSquaredDelta', function() { it('returns the expected value in simple cases', function() { - expect(_ol_geom_flat_closest_.getMaxSquaredDelta( + expect(maxSquaredDelta( flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9); }); @@ -19,23 +19,23 @@ describe('ol.geom.flat.closest', function() { describe('ol.geom.flat.closest.getClosestPoint', function() { it('returns the expected value', function() { - const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta( + const maxDelta = Math.sqrt(maxSquaredDelta( flatCoordinates, 0, flatCoordinates.length, 2, 0)); expect(maxDelta).to.be(3); const closestPoint = [NaN, NaN]; - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0); expect(closestPoint).to.eql([0, 0]); - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1); expect(closestPoint).to.eql([4, 0]); - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4); expect(closestPoint).to.eql([5, 0]); - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000); expect(closestPoint).to.eql([10, 0]); @@ -78,7 +78,7 @@ describe('ol.geom.flat.closest', function() { describe('ol.geom.closet.maSquaredDelta', function() { it('returns the expected value', function() { - expect(_ol_geom_flat_closest_.getMaxSquaredDelta( + expect(maxSquaredDelta( flatCoordinates, 0, flatCoordinates.length, 2, 0)). to.roughlyEqual(1389.1058, 1e-9); }); @@ -88,21 +88,21 @@ describe('ol.geom.flat.closest', function() { describe('ol.geom.flat.closest.getClosestPoint', function() { it('returns the expected value', function() { - const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta( + const maxDelta = Math.sqrt(maxSquaredDelta( flatCoordinates, 0, flatCoordinates.length, 2, 0)); expect(maxDelta).to.roughlyEqual(Math.sqrt(1389.1058), 1e-9); const closestPoint = [NaN, NaN]; - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 0, 0, closestPoint, Infinity)). to.roughlyEqual(110902.405, 1e-9); expect(closestPoint).to.eql([292.41, 159.37]); - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 500, 500, closestPoint, Infinity)). to.roughlyEqual(106407.905, 1e-9); expect(closestPoint).to.eql([671.55, 222.55]); - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, 2, maxDelta, false, 1000, 500, closestPoint, Infinity)). to.roughlyEqual(18229.4425, 1e-9); @@ -121,11 +121,11 @@ describe('ol.geom.flat.closest', function() { describe('ol.geom.flat.closest.getClosestPoint', function() { it('interpolates M coordinates', function() { - const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta( + const maxDelta = Math.sqrt(maxSquaredDelta( flatCoordinates, 0, flatCoordinates.length, stride, 0)); expect(maxDelta).to.roughlyEqual(Math.sqrt(8), 1e-9); const closestPoint = [NaN, NaN]; - expect(_ol_geom_flat_closest_.getClosestPoint( + expect(assignClosestPoint( flatCoordinates, 0, flatCoordinates.length, stride, maxDelta, false, 1, 1, closestPoint, Infinity)). to.roughlyEqual(0, 1e-9); From 6573b308b692d48ea68a45e66148a14440dd19f3 Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 08:57:35 -0600 Subject: [PATCH 09/13] ol/geom/flat/orient export --- src/ol/format/EsriJSON.js | 4 ++-- src/ol/format/MVT.js | 4 ++-- src/ol/geom/MultiPolygon.js | 8 +++---- src/ol/geom/Polygon.js | 8 +++---- src/ol/geom/flat/orient.js | 30 ++++++++++++------------- src/ol/render/webgl/LineStringReplay.js | 4 ++-- src/ol/render/webgl/PolygonReplay.js | 8 +++---- test/spec/ol/geom/flat/orient.test.js | 15 +++++++------ 8 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/ol/format/EsriJSON.js b/src/ol/format/EsriJSON.js index f56d27b99d..c101ac31ad 100644 --- a/src/ol/format/EsriJSON.js +++ b/src/ol/format/EsriJSON.js @@ -17,7 +17,7 @@ import MultiPolygon from '../geom/MultiPolygon.js'; import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; -import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; +import {linearRingIsClockwise} from '../geom/flat/orient.js'; import {assign, isEmpty} from '../obj.js'; import {get as getProjection} from '../proj.js'; @@ -134,7 +134,7 @@ function convertRings(rings, layout) { flatRing.length = 0; deflateCoordinates(flatRing, 0, rings[i], layout.length); // is this ring an outer ring? is it clockwise? - const clockwise = _ol_geom_flat_orient_.linearRingIsClockwise(flatRing, 0, + const clockwise = linearRingIsClockwise(flatRing, 0, flatRing.length, layout.length); if (clockwise) { outerRings.push([rings[i]]); diff --git a/src/ol/format/MVT.js b/src/ol/format/MVT.js index c4379e431e..fa54a2dcff 100644 --- a/src/ol/format/MVT.js +++ b/src/ol/format/MVT.js @@ -16,7 +16,7 @@ import MultiPoint from '../geom/MultiPoint.js'; import MultiPolygon from '../geom/MultiPolygon.js'; import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; -import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; +import {linearRingIsClockwise} from '../geom/flat/orient.js'; import Projection from '../proj/Projection.js'; import Units from '../proj/Units.js'; import RenderFeature from '../render/Feature.js'; @@ -309,7 +309,7 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) { let prevEndIndex = 0; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - if (!_ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates, offset, end, 2)) { + if (!linearRingIsClockwise(flatCoordinates, offset, end, 2)) { endss.push(ends.slice(prevEndIndex, i)); prevEndIndex = i; } diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 9ee2af7e72..6c39b787cb 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -17,7 +17,7 @@ import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; import {getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; -import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; +import {linearRingsAreOriented, orientLinearRingsArray} from '../geom/flat/orient.js'; import {quantizeMultiArray} from '../geom/flat/simplify.js'; /** @@ -183,7 +183,7 @@ MultiPolygon.prototype.getCoordinates = function(opt_right) { let flatCoordinates; if (opt_right !== undefined) { flatCoordinates = this.getOrientedFlatCoordinates().slice(); - _ol_geom_flat_orient_.orientLinearRingss( + orientLinearRingsArray( flatCoordinates, 0, this.endss_, this.stride, opt_right); } else { flatCoordinates = this.flatCoordinates; @@ -238,13 +238,13 @@ MultiPolygon.prototype.getInteriorPoints = function() { MultiPolygon.prototype.getOrientedFlatCoordinates = function() { if (this.orientedRevision_ != this.getRevision()) { const flatCoordinates = this.flatCoordinates; - if (_ol_geom_flat_orient_.linearRingssAreOriented( + if (linearRingsAreOriented( flatCoordinates, 0, this.endss_, this.stride)) { this.orientedFlatCoordinates_ = flatCoordinates; } else { this.orientedFlatCoordinates_ = flatCoordinates.slice(); this.orientedFlatCoordinates_.length = - _ol_geom_flat_orient_.orientLinearRingss( + orientLinearRingsArray( this.orientedFlatCoordinates_, 0, this.endss_, this.stride); } this.orientedRevision_ = this.getRevision(); diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index c2ac483f4e..644d4eb8e8 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -17,7 +17,7 @@ import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import {getInteriorPointOfArray} from '../geom/flat/interiorpoint.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; -import _ol_geom_flat_orient_ from '../geom/flat/orient.js'; +import {linearRingIsOriented, orientLinearRings} from '../geom/flat/orient.js'; import {quantizeArray} from '../geom/flat/simplify.js'; import {modulo} from '../math.js'; @@ -173,7 +173,7 @@ Polygon.prototype.getCoordinates = function(opt_right) { let flatCoordinates; if (opt_right !== undefined) { flatCoordinates = this.getOrientedFlatCoordinates().slice(); - _ol_geom_flat_orient_.orientLinearRings( + orientLinearRings( flatCoordinates, 0, this.ends_, this.stride, opt_right); } else { flatCoordinates = this.flatCoordinates; @@ -279,13 +279,13 @@ Polygon.prototype.getLinearRings = function() { Polygon.prototype.getOrientedFlatCoordinates = function() { if (this.orientedRevision_ != this.getRevision()) { const flatCoordinates = this.flatCoordinates; - if (_ol_geom_flat_orient_.linearRingsAreOriented( + if (linearRingIsOriented( flatCoordinates, 0, this.ends_, this.stride)) { this.orientedFlatCoordinates_ = flatCoordinates; } else { this.orientedFlatCoordinates_ = flatCoordinates.slice(); this.orientedFlatCoordinates_.length = - _ol_geom_flat_orient_.orientLinearRings( + orientLinearRings( this.orientedFlatCoordinates_, 0, this.ends_, this.stride); } this.orientedRevision_ = this.getRevision(); diff --git a/src/ol/geom/flat/orient.js b/src/ol/geom/flat/orient.js index ef0467880a..864e0a35c5 100644 --- a/src/ol/geom/flat/orient.js +++ b/src/ol/geom/flat/orient.js @@ -2,7 +2,6 @@ * @module ol/geom/flat/orient */ import {coordinates as reverseCoordinates} from '../flat/reverse.js'; -const _ol_geom_flat_orient_ = {}; /** @@ -12,7 +11,7 @@ const _ol_geom_flat_orient_ = {}; * @param {number} stride Stride. * @return {boolean} Is clockwise. */ -_ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset, end, stride) { +export function linearRingIsClockwise(flatCoordinates, offset, end, stride) { // http://tinyurl.com/clockwise-method // https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrlinearring.cpp let edge = 0; @@ -26,7 +25,7 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset, y1 = y2; } return edge > 0; -}; +} /** @@ -42,11 +41,11 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset, * (counter-clockwise exterior ring and clockwise interior rings). * @return {boolean} Rings are correctly oriented. */ -_ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) { +export function linearRingIsOriented(flatCoordinates, offset, ends, stride, opt_right) { const right = opt_right !== undefined ? opt_right : false; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( + const isClockwise = linearRingIsClockwise( flatCoordinates, offset, end, stride); if (i === 0) { if ((right && isClockwise) || (!right && !isClockwise)) { @@ -60,7 +59,7 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, offset = end; } return true; -}; +} /** @@ -76,15 +75,15 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, * (counter-clockwise exterior ring and clockwise interior rings). * @return {boolean} Rings are correctly oriented. */ -_ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) { +export function linearRingsAreOriented(flatCoordinates, offset, endss, stride, opt_right) { for (let i = 0, ii = endss.length; i < ii; ++i) { - if (!_ol_geom_flat_orient_.linearRingsAreOriented( + if (!linearRingIsOriented( flatCoordinates, offset, endss[i], stride, opt_right)) { return false; } } return true; -}; +} /** @@ -100,11 +99,11 @@ _ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset * @param {boolean=} opt_right Follow the right-hand rule for orientation. * @return {number} End. */ -_ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends, stride, opt_right) { +export function orientLinearRings(flatCoordinates, offset, ends, stride, opt_right) { const right = opt_right !== undefined ? opt_right : false; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( + const isClockwise = linearRingIsClockwise( flatCoordinates, offset, end, stride); const reverse = i === 0 ? (right && isClockwise) || (!right && !isClockwise) : @@ -115,7 +114,7 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends offset = end; } return offset; -}; +} /** @@ -131,11 +130,10 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends * @param {boolean=} opt_right Follow the right-hand rule for orientation. * @return {number} End. */ -_ol_geom_flat_orient_.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) { +export function orientLinearRingsArray(flatCoordinates, offset, endss, stride, opt_right) { for (let i = 0, ii = endss.length; i < ii; ++i) { - offset = _ol_geom_flat_orient_.orientLinearRings( + offset = orientLinearRings( flatCoordinates, offset, endss[i], stride, opt_right); } return offset; -}; -export default _ol_geom_flat_orient_; +} diff --git a/src/ol/render/webgl/LineStringReplay.js b/src/ol/render/webgl/LineStringReplay.js index 89e411ce5a..fb24b1aff7 100644 --- a/src/ol/render/webgl/LineStringReplay.js +++ b/src/ol/render/webgl/LineStringReplay.js @@ -5,7 +5,7 @@ import {getUid, inherits} from '../../index.js'; import {equals} from '../../array.js'; import {asArray} from '../../color.js'; import {intersects} from '../../extent.js'; -import _ol_geom_flat_orient_ from '../../geom/flat/orient.js'; +import {linearRingIsClockwise} from '../../geom/flat/orient.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import {lineStringIsClosed} from '../../geom/flat/topology.js'; import {isEmpty} from '../../obj.js'; @@ -252,7 +252,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off if (closed) { n = n || numVertices / 7; - sign = _ol_geom_flat_orient_.linearRingIsClockwise([p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]], 0, 6, 2) + sign = linearRingIsClockwise([p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]], 0, 6, 2) ? 1 : -1; numVertices = this.addVertices_(p0, p1, p2, diff --git a/src/ol/render/webgl/PolygonReplay.js b/src/ol/render/webgl/PolygonReplay.js index 75b9fc747a..ae407045ee 100644 --- a/src/ol/render/webgl/PolygonReplay.js +++ b/src/ol/render/webgl/PolygonReplay.js @@ -7,7 +7,7 @@ import {asArray} from '../../color.js'; import {intersects} from '../../extent.js'; import {isEmpty} from '../../obj.js'; import {linearRingContainsXY} from '../../geom/flat/contains.js'; -import _ol_geom_flat_orient_ from '../../geom/flat/orient.js'; +import {linearRingIsClockwise} from '../../geom/flat/orient.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import {fragment, vertex} from '../webgl/polygonreplay/defaultshader.js'; import Locations from '../webgl/polygonreplay/defaultshader/Locations.js'; @@ -140,7 +140,7 @@ WebGLPolygonReplay.prototype.drawCoordinates_ = function( */ WebGLPolygonReplay.prototype.processFlatCoordinates_ = function( flatCoordinates, stride, list, rtree, clockwise) { - const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates, + const isClockwise = linearRingIsClockwise(flatCoordinates, 0, flatCoordinates.length, stride); let i, ii; let n = this.vertices.length / 2; @@ -404,7 +404,7 @@ WebGLPolygonReplay.prototype.clipEars_ = function(list, rtree, simple, ccw) { variableCriterion) { //The diagonal is completely inside the polygon if (simple || p0.reflex === false || p2.reflex === false || - _ol_geom_flat_orient_.linearRingIsClockwise([s0.p0.x, s0.p0.y, p0.x, + linearRingIsClockwise([s0.p0.x, s0.p0.y, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, s3.p1.x, s3.p1.y], 0, 10, 2) === !ccw) { //The diagonal is persumably valid, we have an ear this.indices[numIndices++] = p0.i; @@ -533,7 +533,7 @@ WebGLPolygonReplay.prototype.isClockwise_ = function(list) { flatCoordinates[i++] = seg.p0.y; seg = list.nextItem(); } while (seg !== start); - return _ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates, 0, length, 2); + return linearRingIsClockwise(flatCoordinates, 0, length, 2); }; diff --git a/test/spec/ol/geom/flat/orient.test.js b/test/spec/ol/geom/flat/orient.test.js index cc481c01fd..6dd173317a 100644 --- a/test/spec/ol/geom/flat/orient.test.js +++ b/test/spec/ol/geom/flat/orient.test.js @@ -1,4 +1,5 @@ -import _ol_geom_flat_orient_ from '../../../../../src/ol/geom/flat/orient.js'; +import {linearRingIsClockwise, linearRingIsOriented, + linearRingsAreOriented, orientLinearRings, orientLinearRingsArray} from '../../../../../src/ol/geom/flat/orient.js'; describe('ol.geom.flat.orient', function() { @@ -7,14 +8,14 @@ describe('ol.geom.flat.orient', function() { it('identifies clockwise rings', function() { const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0]; - const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( + const isClockwise = linearRingIsClockwise( flatCoordinates, 0, flatCoordinates.length, 2); expect(isClockwise).to.be(true); }); it('identifies anti-clockwise rings', function() { const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3]; - const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( + const isClockwise = linearRingIsClockwise( flatCoordinates, 0, flatCoordinates.length, 2); expect(isClockwise).to.be(false); }); @@ -22,7 +23,7 @@ describe('ol.geom.flat.orient', function() { }); describe('ol.geom.flat.orient.linearRingsAreOriented()', function() { - const oriented = _ol_geom_flat_orient_.linearRingsAreOriented; + const oriented = linearRingIsOriented; const rightCoords = [ -180, -90, 180, -90, 180, 90, -180, 90, -180, -90, @@ -49,7 +50,7 @@ describe('ol.geom.flat.orient', function() { }); describe('ol.geom.flat.orient.linearRingssAreOriented()', function() { - const oriented = _ol_geom_flat_orient_.linearRingssAreOriented; + const oriented = linearRingsAreOriented; const rightCoords = [ -180, -90, 180, -90, 180, 90, -180, 90, -180, -90, @@ -80,7 +81,7 @@ describe('ol.geom.flat.orient', function() { }); describe('ol.geom.flat.orient.orientLinearRings()', function() { - const orient = _ol_geom_flat_orient_.orientLinearRings; + const orient = orientLinearRings; const rightCoords = [ -180, -90, 180, -90, 180, 90, -180, 90, -180, -90, @@ -117,7 +118,7 @@ describe('ol.geom.flat.orient', function() { }); describe('ol.geom.flat.orient.orientLinearRingss()', function() { - const orient = _ol_geom_flat_orient_.orientLinearRingss; + const orient = orientLinearRingsArray; const rightCoords = [ -180, -90, 180, -90, 180, 90, -180, 90, -180, -90, From abf191289c78e3923f6f5b785c7bfa030ba54139 Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 09:05:12 -0600 Subject: [PATCH 10/13] ol/geom/flat/interpolate export --- src/ol/geom/LineString.js | 6 +++--- src/ol/geom/MultiLineString.js | 6 +++--- src/ol/geom/flat/interpolate.js | 18 ++++++++---------- src/ol/render/Feature.js | 6 +++--- test/spec/ol/geom/flat/interpolate.test.js | 20 ++++++++++---------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index beb3d7a8df..a219e6e8a6 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -10,7 +10,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js'; import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; -import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; +import {interpolatePoint, lineStringCoordinateAtM} from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import {lineStringLength} from '../geom/flat/length.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js'; @@ -143,7 +143,7 @@ LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) { return null; } const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; - return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(this.flatCoordinates, 0, + return lineStringCoordinateAtM(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, m, extrapolate); }; @@ -171,7 +171,7 @@ LineString.prototype.getCoordinates = function() { * @api */ LineString.prototype.getCoordinateAt = function(fraction, opt_dest) { - return _ol_geom_flat_interpolate_.lineString( + return interpolatePoint( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, fraction, opt_dest); }; diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index 7d4e8d1106..dc6a07193f 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -11,7 +11,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js'; import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; -import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; +import {interpolatePoint, lineStringsCoordinateAtM} from '../geom/flat/interpolate.js'; import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; import {douglasPeuckerArray} from '../geom/flat/simplify.js'; @@ -132,7 +132,7 @@ MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_in } const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; const interpolate = opt_interpolate !== undefined ? opt_interpolate : false; - return _ol_geom_flat_interpolate_.lineStringsCoordinateAtM(this.flatCoordinates, 0, + return lineStringsCoordinateAtM(this.flatCoordinates, 0, this.ends_, this.stride, m, extrapolate, interpolate); }; @@ -208,7 +208,7 @@ MultiLineString.prototype.getFlatMidpoints = function() { const stride = this.stride; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - const midpoint = _ol_geom_flat_interpolate_.lineString( + const midpoint = interpolatePoint( flatCoordinates, offset, end, stride, 0.5); extend(midpoints, midpoint); offset = end; diff --git a/src/ol/geom/flat/interpolate.js b/src/ol/geom/flat/interpolate.js index 04d238fa83..37aa638bc3 100644 --- a/src/ol/geom/flat/interpolate.js +++ b/src/ol/geom/flat/interpolate.js @@ -3,7 +3,6 @@ */ import {binarySearch} from '../../array.js'; import {lerp} from '../../math.js'; -const _ol_geom_flat_interpolate_ = {}; /** @@ -15,7 +14,7 @@ const _ol_geom_flat_interpolate_ = {}; * @param {Array.=} opt_dest Destination. * @return {Array.} Destination. */ -_ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, stride, fraction, opt_dest) { +export function interpolatePoint(flatCoordinates, offset, end, stride, fraction, opt_dest) { let pointX = NaN; let pointY = NaN; const n = (end - offset) / stride; @@ -62,7 +61,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s } else { return [pointX, pointY]; } -}; +} /** @@ -74,7 +73,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s * @param {boolean} extrapolate Extrapolate. * @return {ol.Coordinate} Coordinate. */ -_ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, offset, end, stride, m, extrapolate) { +export function lineStringCoordinateAtM(flatCoordinates, offset, end, stride, m, extrapolate) { if (end == offset) { return null; } @@ -123,7 +122,7 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o } coordinate.push(m); return coordinate; -}; +} /** @@ -136,10 +135,10 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o * @param {boolean} interpolate Interpolate. * @return {ol.Coordinate} Coordinate. */ -_ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function( +export function lineStringsCoordinateAtM( flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) { if (interpolate) { - return _ol_geom_flat_interpolate_.lineStringCoordinateAtM( + return lineStringCoordinateAtM( flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate); } let coordinate; @@ -169,11 +168,10 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function( if (m < flatCoordinates[offset + stride - 1]) { return null; } else if (m <= flatCoordinates[end - 1]) { - return _ol_geom_flat_interpolate_.lineStringCoordinateAtM( + return lineStringCoordinateAtM( flatCoordinates, offset, end, stride, m, false); } offset = end; } return null; -}; -export default _ol_geom_flat_interpolate_; +} diff --git a/src/ol/render/Feature.js b/src/ol/render/Feature.js index f72aa7c40f..97450de4c5 100644 --- a/src/ol/render/Feature.js +++ b/src/ol/render/Feature.js @@ -7,7 +7,7 @@ import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCent import GeometryType from '../geom/GeometryType.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; import {getInteriorPointOfArray, getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; -import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js'; +import {interpolatePoint} from '../geom/flat/interpolate.js'; import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; import _ol_transform_ from '../transform.js'; @@ -151,7 +151,7 @@ RenderFeature.prototype.getFlatInteriorPoints = function() { */ RenderFeature.prototype.getFlatMidpoint = function() { if (!this.flatMidpoints_) { - this.flatMidpoints_ = _ol_geom_flat_interpolate_.lineString( + this.flatMidpoints_ = interpolatePoint( this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5); } return this.flatMidpoints_; @@ -169,7 +169,7 @@ RenderFeature.prototype.getFlatMidpoints = function() { const ends = this.ends_; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; - const midpoint = _ol_geom_flat_interpolate_.lineString( + const midpoint = interpolatePoint( flatCoordinates, offset, end, 2, 0.5); extend(this.flatMidpoints_, midpoint); offset = end; diff --git a/test/spec/ol/geom/flat/interpolate.test.js b/test/spec/ol/geom/flat/interpolate.test.js index a8ca28830e..ae65f9e7e6 100644 --- a/test/spec/ol/geom/flat/interpolate.test.js +++ b/test/spec/ol/geom/flat/interpolate.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_interpolate_ from '../../../../../src/ol/geom/flat/interpolate.js'; +import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js'; describe('ol.geom.flat.interpolate', function() { @@ -8,14 +8,14 @@ describe('ol.geom.flat.interpolate', function() { it('returns the expected value for single points', function() { const flatCoordinates = [0, 1]; const point = - _ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 2, 2, 0.5); + interpolatePoint(flatCoordinates, 0, 2, 2, 0.5); expect(point).to.eql([0, 1]); }); it('returns the expected value for simple line segments', function() { const flatCoordinates = [0, 1, 2, 3]; const point = - _ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 4, 2, 0.5); + interpolatePoint(flatCoordinates, 0, 4, 2, 0.5); expect(point).to.eql([1, 2]); }); @@ -23,14 +23,14 @@ describe('ol.geom.flat.interpolate', function() { 'coordinate', function() { const flatCoordinates = [0, 1, 2, 3, 4, 5]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([2, 3]); }); xit('also when vertices are repeated', function() { const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([2, 3]); }); @@ -39,14 +39,14 @@ describe('ol.geom.flat.interpolate', function() { 'two existing coordinates', function() { const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 8, 2, 0.5); expect(point).to.eql([3, 4]); }); xit('also when vertices are repeated', function() { const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 8, 2, 0.5); expect(point).to.eql([3, 4]); }); @@ -54,7 +54,7 @@ describe('ol.geom.flat.interpolate', function() { it('returns the expected value when the coordinates are not evenly spaced', function() { const flatCoordinates = [0, 1, 2, 3, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([3, 4]); }); @@ -62,7 +62,7 @@ describe('ol.geom.flat.interpolate', function() { xit('also when vertices are repeated', function() { const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5); expect(point).to.eql([3, 4]); }); @@ -70,7 +70,7 @@ describe('ol.geom.flat.interpolate', function() { it('returns the expected value when using opt_dest', function() { const flatCoordinates = [0, 1, 2, 3, 6, 7]; - const point = _ol_geom_flat_interpolate_.lineString( + const point = interpolatePoint( flatCoordinates, 0, 6, 2, 0.5, [0, 0]); expect(point).to.eql([3, 4]); }); From 4d27a9eb0e7d036da67fdc8590e34bf4e4ba0676 Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 09:15:07 -0600 Subject: [PATCH 11/13] ol/geom/flat/intersectsextent --- src/ol/geom/LineString.js | 4 +-- src/ol/geom/MultiLineString.js | 4 +-- src/ol/geom/MultiPolygon.js | 4 +-- src/ol/geom/Polygon.js | 4 +-- src/ol/geom/flat/intersectsextent.js | 30 +++++++++---------- .../ol/geom/flat/intersectsextent.test.js | 20 ++++++------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index a219e6e8a6..18d5c5ac2d 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -11,7 +11,7 @@ import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js'; import {deflateCoordinates} from '../geom/flat/deflate.js'; import {inflateCoordinates} from '../geom/flat/inflate.js'; import {interpolatePoint, lineStringCoordinateAtM} from '../geom/flat/interpolate.js'; -import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; +import {intersectsLineString} from '../geom/flat/intersectsextent.js'; import {lineStringLength} from '../geom/flat/length.js'; import {forEach as forEachSegment} from '../geom/flat/segments.js'; import {douglasPeucker} from '../geom/flat/simplify.js'; @@ -229,7 +229,7 @@ LineString.prototype.getType = function() { * @api */ LineString.prototype.intersectsExtent = function(extent) { - return _ol_geom_flat_intersectsextent_.lineString( + return intersectsLineString( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, extent); }; diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index dc6a07193f..93bacc6f60 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -12,7 +12,7 @@ import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closes import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import {interpolatePoint, lineStringsCoordinateAtM} from '../geom/flat/interpolate.js'; -import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; +import {intersectsLineStringArray} from '../geom/flat/intersectsextent.js'; import {douglasPeuckerArray} from '../geom/flat/simplify.js'; /** @@ -247,7 +247,7 @@ MultiLineString.prototype.getType = function() { * @api */ MultiLineString.prototype.intersectsExtent = function(extent) { - return _ol_geom_flat_intersectsextent_.lineStrings( + return intersectsLineStringArray( this.flatCoordinates, 0, this.ends_, this.stride, extent); }; diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 6c39b787cb..0a165505ec 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -16,7 +16,7 @@ import {linearRingssContainsXY} from '../geom/flat/contains.js'; import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js'; import {getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; -import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; +import {intersectsLinearRingMultiArray} from '../geom/flat/intersectsextent.js'; import {linearRingsAreOriented, orientLinearRingsArray} from '../geom/flat/orient.js'; import {quantizeMultiArray} from '../geom/flat/simplify.js'; @@ -344,7 +344,7 @@ MultiPolygon.prototype.getType = function() { * @api */ MultiPolygon.prototype.intersectsExtent = function(extent) { - return _ol_geom_flat_intersectsextent_.linearRingss( + return intersectsLinearRingMultiArray( this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, extent); }; diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 644d4eb8e8..50e7dfccc0 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -16,7 +16,7 @@ import {linearRingsContainsXY} from '../geom/flat/contains.js'; import {deflateCoordinatesArray} from '../geom/flat/deflate.js'; import {inflateCoordinatesArray} from '../geom/flat/inflate.js'; import {getInteriorPointOfArray} from '../geom/flat/interiorpoint.js'; -import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js'; +import {intersectsLinearRingArray} from '../geom/flat/intersectsextent.js'; import {linearRingIsOriented, orientLinearRings} from '../geom/flat/orient.js'; import {quantizeArray} from '../geom/flat/simplify.js'; import {modulo} from '../math.js'; @@ -325,7 +325,7 @@ Polygon.prototype.getType = function() { * @api */ Polygon.prototype.intersectsExtent = function(extent) { - return _ol_geom_flat_intersectsextent_.linearRings( + return intersectsLinearRingArray( this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, extent); }; diff --git a/src/ol/geom/flat/intersectsextent.js b/src/ol/geom/flat/intersectsextent.js index e4dfb1f200..87bb8ea31b 100644 --- a/src/ol/geom/flat/intersectsextent.js +++ b/src/ol/geom/flat/intersectsextent.js @@ -4,7 +4,6 @@ import {containsExtent, createEmpty, extendFlatCoordinates, intersects, intersectsSegment} from '../../extent.js'; import {linearRingContainsXY, linearRingContainsExtent} from '../flat/contains.js'; import {forEach as forEachSegment} from '../flat/segments.js'; -const _ol_geom_flat_intersectsextent_ = {}; /** @@ -15,7 +14,7 @@ const _ol_geom_flat_intersectsextent_ = {}; * @param {ol.Extent} extent Extent. * @return {boolean} True if the geometry and the extent intersect. */ -_ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, end, stride, extent) { +export function intersectsLineString(flatCoordinates, offset, end, stride, extent) { const coordinatesExtent = extendFlatCoordinates( createEmpty(), flatCoordinates, offset, end, stride); if (!intersects(extent, coordinatesExtent)) { @@ -42,7 +41,7 @@ _ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, e function(point1, point2) { return intersectsSegment(extent, point1, point2); }); -}; +} /** @@ -53,16 +52,16 @@ _ol_geom_flat_intersectsextent_.lineString = function(flatCoordinates, offset, e * @param {ol.Extent} extent Extent. * @return {boolean} True if the geometry and the extent intersect. */ -_ol_geom_flat_intersectsextent_.lineStrings = function(flatCoordinates, offset, ends, stride, extent) { +export function intersectsLineStringArray(flatCoordinates, offset, ends, stride, extent) { for (let i = 0, ii = ends.length; i < ii; ++i) { - if (_ol_geom_flat_intersectsextent_.lineString( + if (intersectsLineString( flatCoordinates, offset, ends[i], stride, extent)) { return true; } offset = ends[i]; } return false; -}; +} /** @@ -73,8 +72,8 @@ _ol_geom_flat_intersectsextent_.lineStrings = function(flatCoordinates, offset, * @param {ol.Extent} extent Extent. * @return {boolean} True if the geometry and the extent intersect. */ -_ol_geom_flat_intersectsextent_.linearRing = function(flatCoordinates, offset, end, stride, extent) { - if (_ol_geom_flat_intersectsextent_.lineString( +export function intersectsLinearRing(flatCoordinates, offset, end, stride, extent) { + if (intersectsLineString( flatCoordinates, offset, end, stride, extent)) { return true; } @@ -91,7 +90,7 @@ _ol_geom_flat_intersectsextent_.linearRing = function(flatCoordinates, offset, e return true; } return false; -}; +} /** @@ -102,8 +101,8 @@ _ol_geom_flat_intersectsextent_.linearRing = function(flatCoordinates, offset, e * @param {ol.Extent} extent Extent. * @return {boolean} True if the geometry and the extent intersect. */ -_ol_geom_flat_intersectsextent_.linearRings = function(flatCoordinates, offset, ends, stride, extent) { - if (!_ol_geom_flat_intersectsextent_.linearRing( +export function intersectsLinearRingArray(flatCoordinates, offset, ends, stride, extent) { + if (!intersectsLinearRing( flatCoordinates, offset, ends[0], stride, extent)) { return false; } @@ -116,7 +115,7 @@ _ol_geom_flat_intersectsextent_.linearRings = function(flatCoordinates, offset, } } return true; -}; +} /** @@ -127,15 +126,14 @@ _ol_geom_flat_intersectsextent_.linearRings = function(flatCoordinates, offset, * @param {ol.Extent} extent Extent. * @return {boolean} True if the geometry and the extent intersect. */ -_ol_geom_flat_intersectsextent_.linearRingss = function(flatCoordinates, offset, endss, stride, extent) { +export function intersectsLinearRingMultiArray(flatCoordinates, offset, endss, stride, extent) { for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; - if (_ol_geom_flat_intersectsextent_.linearRings( + if (intersectsLinearRingArray( flatCoordinates, offset, ends, stride, extent)) { return true; } offset = ends[ends.length - 1]; } return false; -}; -export default _ol_geom_flat_intersectsextent_; +} diff --git a/test/spec/ol/geom/flat/intersectsextent.test.js b/test/spec/ol/geom/flat/intersectsextent.test.js index ea7f7cd1c6..5daa17edcc 100644 --- a/test/spec/ol/geom/flat/intersectsextent.test.js +++ b/test/spec/ol/geom/flat/intersectsextent.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_intersectsextent_ from '../../../../../src/ol/geom/flat/intersectsextent.js'; +import {intersectsLinearRing, intersectsLineString} from '../../../../../src/ol/geom/flat/intersectsextent.js'; describe('ol.geom.flat.intersectsextent', function() { @@ -11,7 +11,7 @@ describe('ol.geom.flat.intersectsextent', function() { describe('linestring envelope does not intersect the extent', function() { it('returns false', function() { const extent = [3, 3, 4, 4]; - const r = _ol_geom_flat_intersectsextent_.lineString( + const r = intersectsLineString( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(false); }); @@ -19,7 +19,7 @@ describe('ol.geom.flat.intersectsextent', function() { describe('linestring envelope within the extent', function() { it('returns true', function() { const extent = [-1, -1, 3, 3]; - const r = _ol_geom_flat_intersectsextent_.lineString( + const r = intersectsLineString( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(true); }); @@ -28,7 +28,7 @@ describe('ol.geom.flat.intersectsextent', function() { function() { it('returns true', function() { const extent = [-0.1, 0.1, 2.1, 0.1]; - const r = _ol_geom_flat_intersectsextent_.lineString( + const r = intersectsLineString( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(true); }); @@ -36,7 +36,7 @@ describe('ol.geom.flat.intersectsextent', function() { describe('a segment intersects the extent', function() { it('returns true', function() { const extent = [-0.5, -0.5, 0.5, 0.5]; - const r = _ol_geom_flat_intersectsextent_.lineString( + const r = intersectsLineString( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(true); }); @@ -44,13 +44,13 @@ describe('ol.geom.flat.intersectsextent', function() { describe('no segments intersect the extent', function() { it('returns false', function() { const extent = [0.5, 1.5, 1, 1.75]; - const r = _ol_geom_flat_intersectsextent_.lineString( + const r = intersectsLineString( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(false); }); it('returns false', function() { const extent = [1, 0.25, 1.5, 0.5]; - const r = _ol_geom_flat_intersectsextent_.lineString( + const r = intersectsLineString( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(false); }); @@ -65,7 +65,7 @@ describe('ol.geom.flat.intersectsextent', function() { describe('boundary intersects the extent', function() { it('returns true', function() { const extent = [1.5, 0.0, 2.5, 1.0]; - const r = _ol_geom_flat_intersectsextent_.linearRing( + const r = intersectsLinearRing( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(true); }); @@ -75,7 +75,7 @@ describe('ol.geom.flat.intersectsextent', function() { function() { it('returns false', function() { const extent = [2.0, 0.5, 3, 1.5]; - const r = _ol_geom_flat_intersectsextent_.linearRing( + const r = intersectsLinearRing( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(false); }); @@ -83,7 +83,7 @@ describe('ol.geom.flat.intersectsextent', function() { describe('ring contains the extent', function() { it('returns true', function() { const extent = [0.75, -0.25, 1.25, 0.25]; - const r = _ol_geom_flat_intersectsextent_.linearRing( + const r = intersectsLinearRing( flatCoordinates, 0, flatCoordinates.length, 2, extent); expect(r).to.be(true); }); From b2d920bbf1247a526780f8adb9aa444c1cf3d90b Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 09:22:00 -0600 Subject: [PATCH 12/13] ol/geom/flat/transform export --- src/ol/geom/Geometry.js | 4 ++-- src/ol/geom/SimpleGeometry.js | 10 +++++----- src/ol/geom/flat/transform.js | 18 ++++++++---------- src/ol/render/Feature.js | 4 ++-- src/ol/render/canvas/Immediate.js | 8 ++++---- src/ol/render/canvas/Replay.js | 4 ++-- src/ol/render/canvas/ReplayGroup.js | 4 ++-- src/ol/render/webgl/CircleReplay.js | 4 ++-- src/ol/render/webgl/LineStringReplay.js | 6 +++--- src/ol/render/webgl/PolygonReplay.js | 10 +++++----- test/spec/ol/geom/flat/transform.test.js | 6 +++--- 11 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/ol/geom/Geometry.js b/src/ol/geom/Geometry.js index 52b092973a..ac37cda3f6 100644 --- a/src/ol/geom/Geometry.js +++ b/src/ol/geom/Geometry.js @@ -5,7 +5,7 @@ import {inherits} from '../index.js'; import BaseObject from '../Object.js'; import {createEmpty, getHeight, returnOrUpdate} from '../extent.js'; import {FALSE} from '../functions.js'; -import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; +import {transform2D} from '../geom/flat/transform.js'; import {get as getProjection, getTransform} from '../proj.js'; import Units from '../proj/Units.js'; import _ol_transform_ from '../transform.js'; @@ -265,7 +265,7 @@ Geometry.prototype.transform = function(source, destination) { projectedExtent[0], projectedExtent[3], scale, -scale, 0, 0, 0); - _ol_geom_flat_transform_.transform2D(inCoordinates, 0, inCoordinates.length, stride, + transform2D(inCoordinates, 0, inCoordinates.length, stride, tmpTransform, outCoordinates); return getTransform(source, destination)(inCoordinates, outCoordinates, stride); } : diff --git a/src/ol/geom/SimpleGeometry.js b/src/ol/geom/SimpleGeometry.js index 97e6dc1047..fa85942eb0 100644 --- a/src/ol/geom/SimpleGeometry.js +++ b/src/ol/geom/SimpleGeometry.js @@ -6,7 +6,7 @@ import {FALSE} from '../functions.js'; import {createOrUpdateFromFlatCoordinates, getCenter} from '../extent.js'; import Geometry from '../geom/Geometry.js'; import GeometryLayout from '../geom/GeometryLayout.js'; -import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; +import {rotate, scale, translate, transform2D} from '../geom/flat/transform.js'; import {clear} from '../obj.js'; /** @@ -267,7 +267,7 @@ SimpleGeometry.prototype.rotate = function(angle, anchor) { const flatCoordinates = this.getFlatCoordinates(); if (flatCoordinates) { const stride = this.getStride(); - _ol_geom_flat_transform_.rotate( + rotate( flatCoordinates, 0, flatCoordinates.length, stride, angle, anchor, flatCoordinates); this.changed(); @@ -291,7 +291,7 @@ SimpleGeometry.prototype.scale = function(sx, opt_sy, opt_anchor) { const flatCoordinates = this.getFlatCoordinates(); if (flatCoordinates) { const stride = this.getStride(); - _ol_geom_flat_transform_.scale( + scale( flatCoordinates, 0, flatCoordinates.length, stride, sx, sy, anchor, flatCoordinates); this.changed(); @@ -307,7 +307,7 @@ SimpleGeometry.prototype.translate = function(deltaX, deltaY) { const flatCoordinates = this.getFlatCoordinates(); if (flatCoordinates) { const stride = this.getStride(); - _ol_geom_flat_transform_.translate( + translate( flatCoordinates, 0, flatCoordinates.length, stride, deltaX, deltaY, flatCoordinates); this.changed(); @@ -327,7 +327,7 @@ SimpleGeometry.transform2D = function(simpleGeometry, transform, opt_dest) { return null; } else { const stride = simpleGeometry.getStride(); - return _ol_geom_flat_transform_.transform2D( + return transform2D( flatCoordinates, 0, flatCoordinates.length, stride, transform, opt_dest); } diff --git a/src/ol/geom/flat/transform.js b/src/ol/geom/flat/transform.js index 2493536971..8586d45fbf 100644 --- a/src/ol/geom/flat/transform.js +++ b/src/ol/geom/flat/transform.js @@ -1,7 +1,6 @@ /** * @module ol/geom/flat/transform */ -const _ol_geom_flat_transform_ = {}; /** @@ -13,7 +12,7 @@ const _ol_geom_flat_transform_ = {}; * @param {Array.=} opt_dest Destination. * @return {Array.} Transformed coordinates. */ -_ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) { +export function transform2D(flatCoordinates, offset, end, stride, transform, opt_dest) { const dest = opt_dest ? opt_dest : []; let i = 0; for (let j = offset; j < end; j += stride) { @@ -26,7 +25,7 @@ _ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, st dest.length = i; } return dest; -}; +} /** @@ -39,7 +38,7 @@ _ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, st * @param {Array.=} opt_dest Destination. * @return {Array.} Transformed coordinates. */ -_ol_geom_flat_transform_.rotate = function(flatCoordinates, offset, end, stride, angle, anchor, opt_dest) { +export function rotate(flatCoordinates, offset, end, stride, angle, anchor, opt_dest) { const dest = opt_dest ? opt_dest : []; const cos = Math.cos(angle); const sin = Math.sin(angle); @@ -59,7 +58,7 @@ _ol_geom_flat_transform_.rotate = function(flatCoordinates, offset, end, stride, dest.length = i; } return dest; -}; +} /** @@ -74,7 +73,7 @@ _ol_geom_flat_transform_.rotate = function(flatCoordinates, offset, end, stride, * @param {Array.=} opt_dest Destination. * @return {Array.} Transformed coordinates. */ -_ol_geom_flat_transform_.scale = function(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_dest) { +export function scale(flatCoordinates, offset, end, stride, sx, sy, anchor, opt_dest) { const dest = opt_dest ? opt_dest : []; const anchorX = anchor[0]; const anchorY = anchor[1]; @@ -92,7 +91,7 @@ _ol_geom_flat_transform_.scale = function(flatCoordinates, offset, end, stride, dest.length = i; } return dest; -}; +} /** @@ -105,7 +104,7 @@ _ol_geom_flat_transform_.scale = function(flatCoordinates, offset, end, stride, * @param {Array.=} opt_dest Destination. * @return {Array.} Transformed coordinates. */ -_ol_geom_flat_transform_.translate = function(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) { +export function translate(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) { const dest = opt_dest ? opt_dest : []; let i = 0; for (let j = offset; j < end; j += stride) { @@ -119,5 +118,4 @@ _ol_geom_flat_transform_.translate = function(flatCoordinates, offset, end, stri dest.length = i; } return dest; -}; -export default _ol_geom_flat_transform_; +} diff --git a/src/ol/render/Feature.js b/src/ol/render/Feature.js index 97450de4c5..1d8cad934a 100644 --- a/src/ol/render/Feature.js +++ b/src/ol/render/Feature.js @@ -8,7 +8,7 @@ import GeometryType from '../geom/GeometryType.js'; import {linearRingss as linearRingssCenter} from '../geom/flat/center.js'; import {getInteriorPointOfArray, getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js'; import {interpolatePoint} from '../geom/flat/interpolate.js'; -import _ol_geom_flat_transform_ from '../geom/flat/transform.js'; +import {transform2D} from '../geom/flat/transform.js'; import _ol_transform_ from '../transform.js'; /** @@ -272,7 +272,7 @@ RenderFeature.prototype.transform = function(source, destination) { projectedExtent[0], projectedExtent[3], scale, -scale, 0, 0, 0); - _ol_geom_flat_transform_.transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, + transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, transform, this.flatCoordinates_); }; export default RenderFeature; diff --git a/src/ol/render/canvas/Immediate.js b/src/ol/render/canvas/Immediate.js index a02919714e..386d8268ec 100644 --- a/src/ol/render/canvas/Immediate.js +++ b/src/ol/render/canvas/Immediate.js @@ -11,7 +11,7 @@ import {asColorLike} from '../../colorlike.js'; import {intersects} from '../../extent.js'; import GeometryType from '../../geom/GeometryType.js'; import SimpleGeometry from '../../geom/SimpleGeometry.js'; -import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; +import {transform2D} from '../../geom/flat/transform.js'; import {CANVAS_LINE_DASH} from '../../has.js'; import VectorContext from '../VectorContext.js'; import _ol_render_canvas_ from '../canvas.js'; @@ -252,7 +252,7 @@ CanvasImmediateRenderer.prototype.drawImages_ = function(flatCoordinates, offset if (!this.image_) { return; } - const pixelCoordinates = _ol_geom_flat_transform_.transform2D( + const pixelCoordinates = transform2D( flatCoordinates, offset, end, 2, this.transform_, this.pixelCoordinates_); const context = this.context_; @@ -313,7 +313,7 @@ CanvasImmediateRenderer.prototype.drawText_ = function(flatCoordinates, offset, this.setContextStrokeState_(this.textStrokeState_); } this.setContextTextState_(this.textState_); - const pixelCoordinates = _ol_geom_flat_transform_.transform2D( + const pixelCoordinates = transform2D( flatCoordinates, offset, end, stride, this.transform_, this.pixelCoordinates_); const context = this.context_; @@ -356,7 +356,7 @@ CanvasImmediateRenderer.prototype.drawText_ = function(flatCoordinates, offset, */ CanvasImmediateRenderer.prototype.moveToLineTo_ = function(flatCoordinates, offset, end, stride, close) { const context = this.context_; - const pixelCoordinates = _ol_geom_flat_transform_.transform2D( + const pixelCoordinates = transform2D( flatCoordinates, offset, end, stride, this.transform_, this.pixelCoordinates_); context.moveTo(pixelCoordinates[0], pixelCoordinates[1]); diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index 6580f16312..696d1d9ac8 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -11,7 +11,7 @@ import GeometryType from '../../geom/GeometryType.js'; import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js'; import {lineStringLength} from '../../geom/flat/length.js'; import {drawTextOnPath} from '../../geom/flat/textpath.js'; -import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; +import {transform2D} from '../../geom/flat/transform.js'; import {CANVAS_LINE_DASH} from '../../has.js'; import {isEmpty} from '../../obj.js'; import VectorContext from '../VectorContext.js'; @@ -549,7 +549,7 @@ CanvasReplay.prototype.replay_ = function( if (!this.pixelCoordinates_) { this.pixelCoordinates_ = []; } - pixelCoordinates = _ol_geom_flat_transform_.transform2D( + pixelCoordinates = transform2D( this.coordinates, 0, this.coordinates.length, 2, transform, this.pixelCoordinates_); _ol_transform_.setFromArray(this.renderedTransform_, transform); diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js index 06c3c0c311..4a3c2da437 100644 --- a/src/ol/render/canvas/ReplayGroup.js +++ b/src/ol/render/canvas/ReplayGroup.js @@ -5,7 +5,7 @@ import {inherits} from '../../index.js'; import {numberSafeCompareFunction} from '../../array.js'; import {createCanvasContext2D} from '../../dom.js'; import {buffer, createEmpty, extendCoordinate} from '../../extent.js'; -import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; +import {transform2D} from '../../geom/flat/transform.js'; import {isEmpty} from '../../obj.js'; import ReplayGroup from '../ReplayGroup.js'; import ReplayType from '../ReplayType.js'; @@ -407,7 +407,7 @@ CanvasReplayGroup.prototype.getClipCoords = function(transform) { const maxX = maxExtent[2]; const maxY = maxExtent[3]; const flatClipCoords = [minX, minY, minX, maxY, maxX, maxY, maxX, minY]; - _ol_geom_flat_transform_.transform2D( + transform2D( flatClipCoords, 0, 8, 2, transform, flatClipCoords); return flatClipCoords; }; diff --git a/src/ol/render/webgl/CircleReplay.js b/src/ol/render/webgl/CircleReplay.js index 3da343af9a..086ab71921 100644 --- a/src/ol/render/webgl/CircleReplay.js +++ b/src/ol/render/webgl/CircleReplay.js @@ -6,7 +6,7 @@ import {equals} from '../../array.js'; import {asArray} from '../../color.js'; import {intersects} from '../../extent.js'; import {isEmpty} from '../../obj.js'; -import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; +import {translate} from '../../geom/flat/transform.js'; import {fragment, vertex} from '../webgl/circlereplay/defaultshader.js'; import Locations from '../webgl/circlereplay/defaultshader/Locations.js'; import WebGLReplay from '../webgl/Replay.js'; @@ -134,7 +134,7 @@ WebGLCircleReplay.prototype.drawCircle = function(circleGeometry, feature) { this.radius_ = radius; let flatCoordinates = circleGeometry.getFlatCoordinates(); - flatCoordinates = _ol_geom_flat_transform_.translate(flatCoordinates, 0, 2, + flatCoordinates = translate(flatCoordinates, 0, 2, stride, -this.origin[0], -this.origin[1]); this.drawCoordinates_(flatCoordinates, 0, 2, stride); } else { diff --git a/src/ol/render/webgl/LineStringReplay.js b/src/ol/render/webgl/LineStringReplay.js index fb24b1aff7..f48ea91aba 100644 --- a/src/ol/render/webgl/LineStringReplay.js +++ b/src/ol/render/webgl/LineStringReplay.js @@ -6,7 +6,7 @@ import {equals} from '../../array.js'; import {asArray} from '../../color.js'; import {intersects} from '../../extent.js'; import {linearRingIsClockwise} from '../../geom/flat/orient.js'; -import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; +import {translate} from '../../geom/flat/transform.js'; import {lineStringIsClosed} from '../../geom/flat/topology.js'; import {isEmpty} from '../../obj.js'; import _ol_render_webgl_ from '../webgl.js'; @@ -322,7 +322,7 @@ WebGLLineStringReplay.prototype.drawLineString = function(lineStringGeometry, fe let flatCoordinates = lineStringGeometry.getFlatCoordinates(); const stride = lineStringGeometry.getStride(); if (this.isValid_(flatCoordinates, 0, flatCoordinates.length, stride)) { - flatCoordinates = _ol_geom_flat_transform_.translate(flatCoordinates, 0, flatCoordinates.length, + flatCoordinates = translate(flatCoordinates, 0, flatCoordinates.length, stride, -this.origin[0], -this.origin[1]); if (this.state_.changed) { this.styleIndices_.push(this.indices.length); @@ -349,7 +349,7 @@ WebGLLineStringReplay.prototype.drawMultiLineString = function(multiLineStringGe if (ends.length > 1) { for (i = 1, ii = ends.length; i < ii; ++i) { if (this.isValid_(flatCoordinates, ends[i - 1], ends[i], stride)) { - const lineString = _ol_geom_flat_transform_.translate(flatCoordinates, ends[i - 1], ends[i], + const lineString = translate(flatCoordinates, ends[i - 1], ends[i], stride, -this.origin[0], -this.origin[1]); this.drawCoordinates_( lineString, 0, lineString.length, stride); diff --git a/src/ol/render/webgl/PolygonReplay.js b/src/ol/render/webgl/PolygonReplay.js index ae407045ee..4389e86db6 100644 --- a/src/ol/render/webgl/PolygonReplay.js +++ b/src/ol/render/webgl/PolygonReplay.js @@ -8,7 +8,7 @@ import {intersects} from '../../extent.js'; import {isEmpty} from '../../obj.js'; import {linearRingContainsXY} from '../../geom/flat/contains.js'; import {linearRingIsClockwise} from '../../geom/flat/orient.js'; -import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; +import {translate} from '../../geom/flat/transform.js'; import {fragment, vertex} from '../webgl/polygonreplay/defaultshader.js'; import Locations from '../webgl/polygonreplay/defaultshader/Locations.js'; import WebGLLineStringReplay from '../webgl/LineStringReplay.js'; @@ -761,14 +761,14 @@ WebGLPolygonReplay.prototype.drawMultiPolygon = function(multiPolygonGeometry, f for (i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; if (ends.length > 0) { - const outerRing = _ol_geom_flat_transform_.translate(flatCoordinates, start, ends[0], + const outerRing = translate(flatCoordinates, start, ends[0], stride, -this.origin[0], -this.origin[1]); if (outerRing.length) { const holes = []; let holeFlatCoords; for (j = 1, jj = ends.length; j < jj; ++j) { if (ends[j] !== ends[j - 1]) { - holeFlatCoords = _ol_geom_flat_transform_.translate(flatCoordinates, ends[j - 1], + holeFlatCoords = translate(flatCoordinates, ends[j - 1], ends[j], stride, -this.origin[0], -this.origin[1]); holes.push(holeFlatCoords); } @@ -801,14 +801,14 @@ WebGLPolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) { const stride = polygonGeometry.getStride(); if (ends.length > 0) { const flatCoordinates = polygonGeometry.getFlatCoordinates().map(Number); - const outerRing = _ol_geom_flat_transform_.translate(flatCoordinates, 0, ends[0], + const outerRing = translate(flatCoordinates, 0, ends[0], stride, -this.origin[0], -this.origin[1]); if (outerRing.length) { const holes = []; let i, ii, holeFlatCoords; for (i = 1, ii = ends.length; i < ii; ++i) { if (ends[i] !== ends[i - 1]) { - holeFlatCoords = _ol_geom_flat_transform_.translate(flatCoordinates, ends[i - 1], + holeFlatCoords = translate(flatCoordinates, ends[i - 1], ends[i], stride, -this.origin[0], -this.origin[1]); holes.push(holeFlatCoords); } diff --git a/test/spec/ol/geom/flat/transform.test.js b/test/spec/ol/geom/flat/transform.test.js index 0c06e81fd5..0ea23ea1b7 100644 --- a/test/spec/ol/geom/flat/transform.test.js +++ b/test/spec/ol/geom/flat/transform.test.js @@ -1,6 +1,6 @@ import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js'; import SimpleGeometry from '../../../../../src/ol/geom/SimpleGeometry.js'; -import _ol_geom_flat_transform_ from '../../../../../src/ol/geom/flat/transform.js'; +import {rotate, translate} from '../../../../../src/ol/geom/flat/transform.js'; describe('ol.geom.flat.transform', function() { @@ -75,7 +75,7 @@ describe('ol.geom.flat.transform', function() { const flatCoordinates = multiPolygon.getFlatCoordinates(); const deltaX = 1; const deltaY = 2; - _ol_geom_flat_transform_.translate(flatCoordinates, 0, + translate(flatCoordinates, 0, flatCoordinates.length, multiPolygon.getStride(), deltaX, deltaY, flatCoordinates); expect(flatCoordinates).to.eql([ @@ -92,7 +92,7 @@ describe('ol.geom.flat.transform', function() { const flatCoordinates = multiPolygon.getFlatCoordinates(); const angle = Math.PI / 2; const anchor = [0, 1]; - _ol_geom_flat_transform_.rotate(flatCoordinates, 0, + rotate(flatCoordinates, 0, flatCoordinates.length, multiPolygon.getStride(), angle, anchor, flatCoordinates); expect(flatCoordinates[0]).to.roughlyEqual(1, 1e-9); From 378b73150aa533f225a781700f044af54403abc8 Mon Sep 17 00:00:00 2001 From: raiyni Date: Tue, 13 Feb 2018 09:42:55 -0600 Subject: [PATCH 13/13] update test descriptions to match export paths --- test/spec/ol/geom/flat/closest.test.js | 10 +++++----- test/spec/ol/geom/flat/deflate.test.js | 4 ++-- test/spec/ol/geom/flat/inflate.test.js | 4 ++-- test/spec/ol/geom/flat/interpolate.test.js | 2 +- test/spec/ol/geom/flat/intersectsextent.test.js | 4 ++-- test/spec/ol/geom/flat/length.test.js | 4 ++-- test/spec/ol/geom/flat/orient.test.js | 10 +++++----- test/spec/ol/geom/flat/straightchunk.test.js | 2 +- test/spec/ol/geom/flat/textpath.test.js | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test/spec/ol/geom/flat/closest.test.js b/test/spec/ol/geom/flat/closest.test.js index b35b62bd2f..a6e1d0a973 100644 --- a/test/spec/ol/geom/flat/closest.test.js +++ b/test/spec/ol/geom/flat/closest.test.js @@ -7,7 +7,7 @@ describe('ol.geom.flat.closest', function() { const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0]; - describe('ol.geom.flat.closest.getMaxSquaredDelta', function() { + describe('ol.geom.flat.closest.maxSquaredDelta', function() { it('returns the expected value in simple cases', function() { expect(maxSquaredDelta( @@ -16,7 +16,7 @@ describe('ol.geom.flat.closest', function() { }); - describe('ol.geom.flat.closest.getClosestPoint', function() { + describe('ol.geom.flat.closest.assignClosestPoint', function() { it('returns the expected value', function() { const maxDelta = Math.sqrt(maxSquaredDelta( @@ -75,7 +75,7 @@ describe('ol.geom.flat.closest', function() { 847.16, 458.44, 851.38, 462.79, 853.97, 471.15, 866.36, 480.77 ]; - describe('ol.geom.closet.maSquaredDelta', function() { + describe('ol.geom.closest.maxSquaredDelta', function() { it('returns the expected value', function() { expect(maxSquaredDelta( @@ -85,7 +85,7 @@ describe('ol.geom.flat.closest', function() { }); - describe('ol.geom.flat.closest.getClosestPoint', function() { + describe('ol.geom.flat.closest.assignClosestPoint', function() { it('returns the expected value', function() { const maxDelta = Math.sqrt(maxSquaredDelta( @@ -118,7 +118,7 @@ describe('ol.geom.flat.closest', function() { const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20]; const stride = 4; - describe('ol.geom.flat.closest.getClosestPoint', function() { + describe('ol.geom.flat.closest.assignClosestPoint', function() { it('interpolates M coordinates', function() { const maxDelta = Math.sqrt(maxSquaredDelta( diff --git a/test/spec/ol/geom/flat/deflate.test.js b/test/spec/ol/geom/flat/deflate.test.js index a7f34e2f91..0395610176 100644 --- a/test/spec/ol/geom/flat/deflate.test.js +++ b/test/spec/ol/geom/flat/deflate.test.js @@ -3,7 +3,7 @@ import {deflateCoordinates, deflateCoordinatesArray} from '../../../../../src/ol describe('ol.geom.flat.deflate', function() { - describe('ol.geom.flat.deflate.coordinates', function() { + describe('ol.geom.flat.deflate.deflateCoordinates', function() { let flatCoordinates; beforeEach(function() { @@ -19,7 +19,7 @@ describe('ol.geom.flat.deflate', function() { }); - describe('ol.geom.flat.deflate.coordinatess', function() { + describe('ol.geom.flat.deflate.deflateCoordinatesArray', function() { let flatCoordinates; beforeEach(function() { diff --git a/test/spec/ol/geom/flat/inflate.test.js b/test/spec/ol/geom/flat/inflate.test.js index 356f5b87a2..a1e46931c8 100644 --- a/test/spec/ol/geom/flat/inflate.test.js +++ b/test/spec/ol/geom/flat/inflate.test.js @@ -3,7 +3,7 @@ import {inflateCoordinates, inflateCoordinatesArray} from '../../../../../src/ol describe('ol.geom.flat.inflate', function() { - describe('ol.geom.flat.inflate.coordinates', function() { + describe('ol.geom.flat.inflate.inflateCoordinates', function() { it('inflates coordinates', function() { const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2); @@ -12,7 +12,7 @@ describe('ol.geom.flat.inflate', function() { }); - describe('ol.geom.flat.inflate.coordinatess', function() { + describe('ol.geom.flat.inflate.inflateCoordinatesArray', function() { it('inflates arrays of coordinates', function() { const coordinatess = inflateCoordinatesArray( diff --git a/test/spec/ol/geom/flat/interpolate.test.js b/test/spec/ol/geom/flat/interpolate.test.js index ae65f9e7e6..b0ee7434bc 100644 --- a/test/spec/ol/geom/flat/interpolate.test.js +++ b/test/spec/ol/geom/flat/interpolate.test.js @@ -3,7 +3,7 @@ import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js'; describe('ol.geom.flat.interpolate', function() { - describe('ol.geom.flat.interpolate.lineString', function() { + describe('ol.geom.flat.interpolate.interpolatePoint', function() { it('returns the expected value for single points', function() { const flatCoordinates = [0, 1]; diff --git a/test/spec/ol/geom/flat/intersectsextent.test.js b/test/spec/ol/geom/flat/intersectsextent.test.js index 5daa17edcc..0e7927fadb 100644 --- a/test/spec/ol/geom/flat/intersectsextent.test.js +++ b/test/spec/ol/geom/flat/intersectsextent.test.js @@ -3,7 +3,7 @@ import {intersectsLinearRing, intersectsLineString} from '../../../../../src/ol/ describe('ol.geom.flat.intersectsextent', function() { - describe('ol.geom.flat.intersectsextent.lineString', function() { + describe('ol.geom.flat.intersectsextent.intersectsLineString', function() { let flatCoordinates; beforeEach(function() { flatCoordinates = [0, 0, 1, 1, 2, 2]; @@ -57,7 +57,7 @@ describe('ol.geom.flat.intersectsextent', function() { }); }); - describe('ol.geom.flat.intersectsextent.linearRing', function() { + describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function() { let flatCoordinates; beforeEach(function() { flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0]; diff --git a/test/spec/ol/geom/flat/length.test.js b/test/spec/ol/geom/flat/length.test.js index 030608b545..ff5720385a 100644 --- a/test/spec/ol/geom/flat/length.test.js +++ b/test/spec/ol/geom/flat/length.test.js @@ -3,7 +3,7 @@ import {lineStringLength, linearRingLength} from '../../../../../src/ol/geom/fla describe('ol.geom.flat.length', function() { - describe('ol.geom.flat.length.lineString', function() { + describe('ol.geom.flat.length.lineStringLength', function() { describe('stride = 2', function() { const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1]; @@ -66,7 +66,7 @@ describe('ol.geom.flat.length', function() { }); }); - describe('ol.geom.flat.length.linearRing', function() { + describe('ol.geom.flat.length.linearRingLength', function() { it('calculates the total length of a simple linearRing', function() { const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1]; diff --git a/test/spec/ol/geom/flat/orient.test.js b/test/spec/ol/geom/flat/orient.test.js index 6dd173317a..610e741008 100644 --- a/test/spec/ol/geom/flat/orient.test.js +++ b/test/spec/ol/geom/flat/orient.test.js @@ -4,7 +4,7 @@ import {linearRingIsClockwise, linearRingIsOriented, describe('ol.geom.flat.orient', function() { - describe('ol.geom.flat.orient.linearRingIsClockwise()', function() { + describe('ol.geom.flat.orient.linearRingIsClockwise', function() { it('identifies clockwise rings', function() { const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0]; @@ -22,7 +22,7 @@ describe('ol.geom.flat.orient', function() { }); - describe('ol.geom.flat.orient.linearRingsAreOriented()', function() { + describe('ol.geom.flat.orient.linearRingIsOriented', function() { const oriented = linearRingIsOriented; const rightCoords = [ @@ -49,7 +49,7 @@ describe('ol.geom.flat.orient', function() { }); - describe('ol.geom.flat.orient.linearRingssAreOriented()', function() { + describe('ol.geom.flat.orient.linearRingsAreOriented', function() { const oriented = linearRingsAreOriented; const rightCoords = [ @@ -80,7 +80,7 @@ describe('ol.geom.flat.orient', function() { }); - describe('ol.geom.flat.orient.orientLinearRings()', function() { + describe('ol.geom.flat.orient.orientLinearRings', function() { const orient = orientLinearRings; const rightCoords = [ @@ -117,7 +117,7 @@ describe('ol.geom.flat.orient', function() { }); - describe('ol.geom.flat.orient.orientLinearRingss()', function() { + describe('ol.geom.flat.orient.orientLinearRingsArray', function() { const orient = orientLinearRingsArray; const rightCoords = [ diff --git a/test/spec/ol/geom/flat/straightchunk.test.js b/test/spec/ol/geom/flat/straightchunk.test.js index 7b58017117..3283665741 100644 --- a/test/spec/ol/geom/flat/straightchunk.test.js +++ b/test/spec/ol/geom/flat/straightchunk.test.js @@ -3,7 +3,7 @@ import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js'; describe('ol.geom.flat.straightchunk', function() { - describe('ol.geom.flat.straightchunk.lineString', function() { + describe('ol.geom.flat.straightchunk.matchingChunk', function() { describe('single segment with stride == 3', function() { const flatCoords = [0, 0, 42, 1, 1, 42]; diff --git a/test/spec/ol/geom/flat/textpath.test.js b/test/spec/ol/geom/flat/textpath.test.js index 302f312b05..b0e3581ae5 100644 --- a/test/spec/ol/geom/flat/textpath.test.js +++ b/test/spec/ol/geom/flat/textpath.test.js @@ -1,7 +1,7 @@ import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js'; import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js'; -describe('textpath', function() { +describe('ol.geom.flat.drawTextOnPath', function() { const horizontal = [0, 0, 100, 0]; const vertical = [0, 0, 0, 100];