From f5a4fcd3ac0c9ff9bc7949e07dddfb6825d29776 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 10 Feb 2018 08:47:16 +0100 Subject: [PATCH 1/5] Remove private static members from ol/geom/GeometryCollection --- src/ol/geom/GeometryCollection.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ol/geom/GeometryCollection.js b/src/ol/geom/GeometryCollection.js index 46a68ad230..3319327956 100644 --- a/src/ol/geom/GeometryCollection.js +++ b/src/ol/geom/GeometryCollection.js @@ -36,16 +36,15 @@ inherits(GeometryCollection, Geometry); /** * @param {Array.} geometries Geometries. - * @private * @return {Array.} Cloned geometries. */ -GeometryCollection.cloneGeometries_ = function(geometries) { +function cloneGeometries(geometries) { const clonedGeometries = []; for (let i = 0, ii = geometries.length; i < ii; ++i) { clonedGeometries.push(geometries[i].clone()); } return clonedGeometries; -}; +} /** @@ -140,7 +139,7 @@ GeometryCollection.prototype.computeExtent = function(extent) { * @api */ GeometryCollection.prototype.getGeometries = function() { - return GeometryCollection.cloneGeometries_(this.geometries_); + return cloneGeometries(this.geometries_); }; @@ -262,8 +261,7 @@ GeometryCollection.prototype.scale = function(sx, opt_sy, opt_anchor) { * @api */ GeometryCollection.prototype.setGeometries = function(geometries) { - this.setGeometriesArray( - GeometryCollection.cloneGeometries_(geometries)); + this.setGeometriesArray(cloneGeometries(geometries)); }; From 11f464f7ff1c7979d1392d53ebd0a11db0e4efaa Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 10 Feb 2018 08:54:58 +0100 Subject: [PATCH 2/5] Remove private static members from ol/render/canvas/ReplayGroup --- src/ol/render/canvas/ReplayGroup.js | 71 +++++++++---------- .../spec/ol/render/canvas/replaygroup.test.js | 4 +- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js index bdf2577fa1..06c3c0c311 100644 --- a/src/ol/render/canvas/ReplayGroup.js +++ b/src/ol/render/canvas/ReplayGroup.js @@ -17,6 +17,22 @@ import CanvasTextReplay from '../canvas/TextReplay.js'; import _ol_render_replay_ from '../replay.js'; import _ol_transform_ from '../../transform.js'; + +/** + * @type {Object.)>} + */ +const BATCH_CONSTRUCTORS = { + 'Circle': CanvasPolygonReplay, + 'Default': CanvasReplay, + 'Image': CanvasImageReplay, + 'LineString': CanvasLineStringReplay, + 'Polygon': CanvasPolygonReplay, + 'Text': CanvasTextReplay +}; + + /** * @constructor * @extends {ol.render.ReplayGroup} @@ -109,9 +125,8 @@ inherits(CanvasReplayGroup, ReplayGroup); * This cache is used for storing calculated pixel circles for increasing performance. * It is a static property to allow each Replaygroup to access it. * @type {Object.>>} - * @private */ -CanvasReplayGroup.circleArrayCache_ = { +const circleArrayCache = { 0: [[true]] }; @@ -122,9 +137,8 @@ CanvasReplayGroup.circleArrayCache_ = { * @param {Array.>} array The array that will be altered. * @param {number} x X coordinate. * @param {number} y Y coordinate. - * @private */ -CanvasReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) { +function fillCircleArrayRowToMiddle(array, x, y) { let i; const radius = Math.floor(array.length / 2); if (x >= radius) { @@ -136,7 +150,7 @@ CanvasReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) { array[i][y] = true; } } -}; +} /** @@ -146,11 +160,10 @@ CanvasReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) { * A cache is used to increase performance. * @param {number} radius Radius. * @returns {Array.>} An array with marked circle points. - * @private */ -CanvasReplayGroup.getCircleArray_ = function(radius) { - if (CanvasReplayGroup.circleArrayCache_[radius] !== undefined) { - return CanvasReplayGroup.circleArrayCache_[radius]; +export function getCircleArray(radius) { + if (circleArrayCache[radius] !== undefined) { + return circleArrayCache[radius]; } const arraySize = radius * 2 + 1; @@ -164,14 +177,14 @@ CanvasReplayGroup.getCircleArray_ = function(radius) { let error = 0; while (x >= y) { - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + x, radius + y); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + y, radius + x); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - y, radius + x); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - x, radius + y); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - x, radius - y); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - y, radius - x); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + y, radius - x); - CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + x, radius - y); + fillCircleArrayRowToMiddle(arr, radius + x, radius + y); + fillCircleArrayRowToMiddle(arr, radius + y, radius + x); + fillCircleArrayRowToMiddle(arr, radius - y, radius + x); + fillCircleArrayRowToMiddle(arr, radius - x, radius + y); + fillCircleArrayRowToMiddle(arr, radius - x, radius - y); + fillCircleArrayRowToMiddle(arr, radius - y, radius - x); + fillCircleArrayRowToMiddle(arr, radius + y, radius - x); + fillCircleArrayRowToMiddle(arr, radius + x, radius - y); y++; error += 1 + 2 * y; @@ -181,9 +194,9 @@ CanvasReplayGroup.getCircleArray_ = function(radius) { } } - CanvasReplayGroup.circleArrayCache_[radius] = arr; + circleArrayCache[radius] = arr; return arr; -}; +} /** @@ -312,7 +325,7 @@ CanvasReplayGroup.prototype.forEachFeatureAtCoordinate = function( buffer(hitExtent, resolution * (this.renderBuffer_ + hitTolerance), hitExtent); } - const mask = CanvasReplayGroup.getCircleArray_(hitTolerance); + const mask = getCircleArray(hitTolerance); let declutteredFeatures; if (this.declutterTree_) { declutteredFeatures = this.declutterTree_.all().map(function(entry) { @@ -412,7 +425,7 @@ CanvasReplayGroup.prototype.getReplay = function(zIndex, replayType) { } let replay = replays[replayType]; if (replay === undefined) { - const Constructor = CanvasReplayGroup.BATCH_CONSTRUCTORS_[replayType]; + const Constructor = BATCH_CONSTRUCTORS[replayType]; replay = new Constructor(this.tolerance_, this.maxExtent_, this.resolution_, this.pixelRatio_, this.overlaps_, this.declutterTree_); replays[replayType] = replay; @@ -487,20 +500,4 @@ CanvasReplayGroup.prototype.replay = function(context, context.restore(); }; - -/** - * @const - * @private - * @type {Object.)>} - */ -CanvasReplayGroup.BATCH_CONSTRUCTORS_ = { - 'Circle': CanvasPolygonReplay, - 'Default': CanvasReplay, - 'Image': CanvasImageReplay, - 'LineString': CanvasLineStringReplay, - 'Polygon': CanvasPolygonReplay, - 'Text': CanvasTextReplay -}; export default CanvasReplayGroup; diff --git a/test/spec/ol/render/canvas/replaygroup.test.js b/test/spec/ol/render/canvas/replaygroup.test.js index 2c23639f2d..ac00a62a22 100644 --- a/test/spec/ol/render/canvas/replaygroup.test.js +++ b/test/spec/ol/render/canvas/replaygroup.test.js @@ -1,4 +1,4 @@ -import CanvasReplayGroup from '../../../../../src/ol/render/canvas/ReplayGroup.js'; +import {getCircleArray} from '../../../../../src/ol/render/canvas/ReplayGroup.js'; describe('ol.render.canvas.ReplayGroup', function() { @@ -8,7 +8,7 @@ describe('ol.render.canvas.ReplayGroup', function() { const radius = 10; const minRadiusSq = Math.pow(radius - Math.SQRT2, 2); const maxRadiusSq = Math.pow(radius + Math.SQRT2, 2); - const circleArray = CanvasReplayGroup.getCircleArray_(radius); + const circleArray = getCircleArray(radius); const size = radius * 2 + 1; expect(circleArray.length).to.be(size); From 2e6bc97fd4ab35c8f9626149bc99f253bb122e61 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 10 Feb 2018 08:58:07 +0100 Subject: [PATCH 3/5] Remove private static members from ol/render/webgl/LineStringReplay --- src/ol/render/webgl/LineStringReplay.js | 62 +++++++++++++------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/ol/render/webgl/LineStringReplay.js b/src/ol/render/webgl/LineStringReplay.js index 1e0eb18d7f..89e411ce5a 100644 --- a/src/ol/render/webgl/LineStringReplay.js +++ b/src/ol/render/webgl/LineStringReplay.js @@ -16,6 +16,23 @@ import Locations from '../webgl/linestringreplay/defaultshader/Locations.js'; import _ol_webgl_ from '../../webgl.js'; import WebGLBuffer from '../../webgl/Buffer.js'; + +/** + * @enum {number} + */ +const Instruction = { + ROUND: 2, + BEGIN_LINE: 3, + END_LINE: 5, + BEGIN_LINE_CAP: 7, + END_LINE_CAP: 11, + BEVEL_FIRST: 13, + BEVEL_SECOND: 17, + MITER_BOTTOM: 19, + MITER_TOP: 23 +}; + + /** * @constructor * @extends {ol.render.webgl.Replay} @@ -85,7 +102,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off let numVertices = this.vertices.length; let numIndices = this.indices.length; //To save a vertex, the direction of a point is a product of the sign (1 or -1), a prime from - //ol.render.webgl.LineStringReplay.Instruction_, and a rounding factor (1 or 2). If the product is even, + //Instruction, and a rounding factor (1 or 2). If the product is even, //we round it. If it is odd, we don't. const lineJoin = this.state_.lineJoin === 'bevel' ? 0 : this.state_.lineJoin === 'miter' ? 1 : 2; @@ -121,10 +138,10 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off if (lineCap) { numVertices = this.addVertices_([0, 0], p1, p2, - lastSign * WebGLLineStringReplay.Instruction_.BEGIN_LINE_CAP * lineCap, numVertices); + lastSign * Instruction.BEGIN_LINE_CAP * lineCap, numVertices); numVertices = this.addVertices_([0, 0], p1, p2, - -lastSign * WebGLLineStringReplay.Instruction_.BEGIN_LINE_CAP * lineCap, numVertices); + -lastSign * Instruction.BEGIN_LINE_CAP * lineCap, numVertices); this.indices[numIndices++] = n + 2; this.indices[numIndices++] = n; @@ -137,10 +154,10 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off } numVertices = this.addVertices_([0, 0], p1, p2, - lastSign * WebGLLineStringReplay.Instruction_.BEGIN_LINE * (lineCap || 1), numVertices); + lastSign * Instruction.BEGIN_LINE * (lineCap || 1), numVertices); numVertices = this.addVertices_([0, 0], p1, p2, - -lastSign * WebGLLineStringReplay.Instruction_.BEGIN_LINE * (lineCap || 1), numVertices); + -lastSign * Instruction.BEGIN_LINE * (lineCap || 1), numVertices); lastIndex = numVertices / 7 - 1; @@ -156,10 +173,10 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off p0 = p0 || [0, 0]; numVertices = this.addVertices_(p0, p1, [0, 0], - lastSign * WebGLLineStringReplay.Instruction_.END_LINE * (lineCap || 1), numVertices); + lastSign * Instruction.END_LINE * (lineCap || 1), numVertices); numVertices = this.addVertices_(p0, p1, [0, 0], - -lastSign * WebGLLineStringReplay.Instruction_.END_LINE * (lineCap || 1), numVertices); + -lastSign * Instruction.END_LINE * (lineCap || 1), numVertices); this.indices[numIndices++] = n; this.indices[numIndices++] = lastIndex - 1; @@ -171,10 +188,10 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off if (lineCap) { numVertices = this.addVertices_(p0, p1, [0, 0], - lastSign * WebGLLineStringReplay.Instruction_.END_LINE_CAP * lineCap, numVertices); + lastSign * Instruction.END_LINE_CAP * lineCap, numVertices); numVertices = this.addVertices_(p0, p1, [0, 0], - -lastSign * WebGLLineStringReplay.Instruction_.END_LINE_CAP * lineCap, numVertices); + -lastSign * Instruction.END_LINE_CAP * lineCap, numVertices); this.indices[numIndices++] = n + 2; this.indices[numIndices++] = n; @@ -197,13 +214,13 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off ? -1 : 1; numVertices = this.addVertices_(p0, p1, p2, - sign * WebGLLineStringReplay.Instruction_.BEVEL_FIRST * (lineJoin || 1), numVertices); + sign * Instruction.BEVEL_FIRST * (lineJoin || 1), numVertices); numVertices = this.addVertices_(p0, p1, p2, - sign * WebGLLineStringReplay.Instruction_.BEVEL_SECOND * (lineJoin || 1), numVertices); + sign * Instruction.BEVEL_SECOND * (lineJoin || 1), numVertices); numVertices = this.addVertices_(p0, p1, p2, - -sign * WebGLLineStringReplay.Instruction_.MITER_BOTTOM * (lineJoin || 1), numVertices); + -sign * Instruction.MITER_BOTTOM * (lineJoin || 1), numVertices); if (i > offset) { this.indices[numIndices++] = n; @@ -225,7 +242,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off //Add miter if (lineJoin) { numVertices = this.addVertices_(p0, p1, p2, - sign * WebGLLineStringReplay.Instruction_.MITER_TOP * lineJoin, numVertices); + sign * Instruction.MITER_TOP * lineJoin, numVertices); this.indices[numIndices++] = n + 1; this.indices[numIndices++] = n + 3; @@ -239,10 +256,10 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off ? 1 : -1; numVertices = this.addVertices_(p0, p1, p2, - sign * WebGLLineStringReplay.Instruction_.BEVEL_FIRST * (lineJoin || 1), numVertices); + sign * Instruction.BEVEL_FIRST * (lineJoin || 1), numVertices); numVertices = this.addVertices_(p0, p1, p2, - -sign * WebGLLineStringReplay.Instruction_.MITER_BOTTOM * (lineJoin || 1), numVertices); + -sign * Instruction.MITER_BOTTOM * (lineJoin || 1), numVertices); this.indices[numIndices++] = n; this.indices[numIndices++] = lastIndex - 1; @@ -664,19 +681,4 @@ WebGLLineStringReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeS } }; -/** - * @enum {number} - * @private - */ -WebGLLineStringReplay.Instruction_ = { - ROUND: 2, - BEGIN_LINE: 3, - END_LINE: 5, - BEGIN_LINE_CAP: 7, - END_LINE_CAP: 11, - BEVEL_FIRST: 13, - BEVEL_SECOND: 17, - MITER_BOTTOM: 19, - MITER_TOP: 23 -}; export default WebGLLineStringReplay; From 6838d59e64ef408dec77cadf6875a2d446462260 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 10 Feb 2018 09:01:02 +0100 Subject: [PATCH 4/5] Remove private static members from ol/render/webgl/ReplayGroup --- src/ol/render/webgl/ReplayGroup.js | 58 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/ol/render/webgl/ReplayGroup.js b/src/ol/render/webgl/ReplayGroup.js index db0c78a5f2..c2f787ad10 100644 --- a/src/ol/render/webgl/ReplayGroup.js +++ b/src/ol/render/webgl/ReplayGroup.js @@ -13,6 +13,25 @@ import WebGLLineStringReplay from '../webgl/LineStringReplay.js'; import WebGLPolygonReplay from '../webgl/PolygonReplay.js'; import WebGLTextReplay from '../webgl/TextReplay.js'; +/** + * @type {Array.} + */ +const HIT_DETECTION_SIZE = [1, 1]; + +/** + * @type {Object.} + */ +const BATCH_CONSTRUCTORS = { + 'Circle': WebGLCircleReplay, + 'Image': WebGLImageReplay, + 'LineString': WebGLLineStringReplay, + 'Polygon': WebGLPolygonReplay, + 'Text': WebGLTextReplay +}; + + /** * @constructor * @extends {ol.render.ReplayGroup} @@ -115,7 +134,7 @@ WebGLReplayGroup.prototype.getReplay = function(zIndex, replayType) { /** * @type {Function} */ - const Constructor = WebGLReplayGroup.BATCH_CONSTRUCTORS_[replayType]; + const Constructor = BATCH_CONSTRUCTORS[replayType]; replay = new Constructor(this.tolerance_, this.maxExtent_); replays[replayType] = replay; } @@ -246,12 +265,12 @@ WebGLReplayGroup.prototype.forEachFeatureAtCoordinate = function( } return this.replayHitDetection_(context, - coordinate, resolution, rotation, WebGLReplayGroup.HIT_DETECTION_SIZE_, + coordinate, resolution, rotation, HIT_DETECTION_SIZE, pixelRatio, opacity, skippedFeaturesHash, /** - * @param {ol.Feature|ol.render.Feature} feature Feature. - * @return {?} Callback result. - */ + * @param {ol.Feature|ol.render.Feature} feature Feature. + * @return {?} Callback result. + */ function(feature) { const imageData = new Uint8Array(4); gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, imageData); @@ -287,12 +306,12 @@ WebGLReplayGroup.prototype.hasFeatureAtCoordinate = function( gl.FRAMEBUFFER, context.getHitDetectionFramebuffer()); const hasFeature = this.replayHitDetection_(context, - coordinate, resolution, rotation, WebGLReplayGroup.HIT_DETECTION_SIZE_, + coordinate, resolution, rotation, HIT_DETECTION_SIZE, pixelRatio, opacity, skippedFeaturesHash, /** - * @param {ol.Feature|ol.render.Feature} feature Feature. - * @return {boolean} Is there a feature? - */ + * @param {ol.Feature|ol.render.Feature} feature Feature. + * @return {boolean} Is there a feature? + */ function(feature) { const imageData = new Uint8Array(4); gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, imageData); @@ -302,25 +321,4 @@ WebGLReplayGroup.prototype.hasFeatureAtCoordinate = function( return hasFeature !== undefined; }; -/** - * @const - * @private - * @type {Array.} - */ -WebGLReplayGroup.HIT_DETECTION_SIZE_ = [1, 1]; - -/** - * @const - * @private - * @type {Object.} - */ -WebGLReplayGroup.BATCH_CONSTRUCTORS_ = { - 'Circle': WebGLCircleReplay, - 'Image': WebGLImageReplay, - 'LineString': WebGLLineStringReplay, - 'Polygon': WebGLPolygonReplay, - 'Text': WebGLTextReplay -}; export default WebGLReplayGroup; From 84c74eec71712a335abea96ca21413ac9711cf9c Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 10 Feb 2018 09:13:42 +0100 Subject: [PATCH 5/5] Remove private static members from ol/renderer/Map --- src/ol/renderer/Map.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ol/renderer/Map.js b/src/ol/renderer/Map.js index 6969f7ef5f..847e76cb2d 100644 --- a/src/ol/renderer/Map.js +++ b/src/ol/renderer/Map.js @@ -24,7 +24,6 @@ const MapRenderer = function(container, map) { Disposable.call(this); - /** * @private * @type {ol.PluggableMap} @@ -81,11 +80,10 @@ MapRenderer.prototype.removeLayerRenderers = function() { /** * @param {ol.PluggableMap} map Map. * @param {olx.FrameState} frameState Frame state. - * @private */ -MapRenderer.expireIconCache_ = function(map, frameState) { +function expireIconCache(map, frameState) { iconImageCache.expire(); -}; +} /** @@ -314,9 +312,7 @@ MapRenderer.prototype.removeUnusedLayerRenderers_ = function(map, frameState) { * @protected */ MapRenderer.prototype.scheduleExpireIconCache = function(frameState) { - frameState.postRenderFunctions.push( - /** @type {ol.PostRenderFunction} */ (MapRenderer.expireIconCache_) - ); + frameState.postRenderFunctions.push(/** @type {ol.PostRenderFunction} */ (expireIconCache)); };