diff --git a/src/ol/geom2/geom2.js b/src/ol/geom2/geom2.js deleted file mode 100644 index 1cdfd5228a..0000000000 --- a/src/ol/geom2/geom2.js +++ /dev/null @@ -1,67 +0,0 @@ -goog.provide('ol.geom2'); - -goog.require('goog.asserts'); -goog.require('ol.Extent'); -goog.require('ol.extent'); - - -/** - * @param {ol.structs.Buffer} buf Buffer. - * @param {number} dim Dimension. - * @return {ol.Extent} Extent. - */ -ol.geom2.getExtent = function(buf, dim) { - var extent = ol.extent.createEmpty(); - var bufArr = buf.getArray(); - buf.forEachRange(function(start, stop) { - var x, y; - for (var i = start; i < stop; i += dim) { - x = bufArr[i]; - y = bufArr[i + 1]; - extent[0] = Math.min(extent[0], x); - extent[1] = Math.min(extent[1], y); - extent[2] = Math.max(extent[2], x); - extent[3] = Math.max(extent[3], y); - } - }); - return extent; -}; - - -/** - * @param {Array.} arr Array. - * @param {number} offset Offset. - * @param {Array.>} unpackedPoints Unpacked points. - * @param {number} dim Dimension. - * @return {number} Offset. - */ -ol.geom2.packPoints = function(arr, offset, unpackedPoints, dim) { - var n = unpackedPoints.length; - var i, j, point; - for (i = 0; i < n; ++i) { - point = unpackedPoints[i]; - goog.asserts.assert(point.length == dim); - for (j = 0; j < dim; ++j) { - arr[offset++] = point[j]; - } - } - return offset; -}; - - -/** - * @param {Array.} arr Array. - * @param {number} offset Offset. - * @param {number} end End. - * @param {number} dim Dimension. - * @return {Array.>} Unpacked points. - */ -ol.geom2.unpackPoints = function(arr, offset, end, dim) { - var unpackedPoints = new Array((end - offset) / dim); - var i = 0; - var j; - for (j = offset; j < end; j += dim) { - unpackedPoints[i++] = arr.slice(j, j + dim); - } - return unpackedPoints; -}; diff --git a/src/ol/geom2/linestringcollection.exports b/src/ol/geom2/linestringcollection.exports deleted file mode 100644 index 6f7b393e71..0000000000 --- a/src/ol/geom2/linestringcollection.exports +++ /dev/null @@ -1,2 +0,0 @@ -@exportSymbol ol.geom2.LineStringCollection -@exportSymbol ol.geom2.LineStringCollection.pack diff --git a/src/ol/geom2/linestringcollection.js b/src/ol/geom2/linestringcollection.js deleted file mode 100644 index b07455e638..0000000000 --- a/src/ol/geom2/linestringcollection.js +++ /dev/null @@ -1,211 +0,0 @@ -goog.provide('ol.geom2.LineString'); -goog.provide('ol.geom2.LineStringCollection'); - -goog.require('goog.array'); -goog.require('goog.asserts'); -goog.require('goog.object'); -goog.require('ol.geom2'); -goog.require('ol.structs.Buffer'); - - -/** - * @typedef {Array.>} - */ -ol.geom2.LineString; - - - -/** - * This is an internal class that will be removed from the API. - * @constructor - * @param {ol.structs.Buffer} buf Buffer. - * @param {Object.=} opt_ranges Ranges. - * @param {number=} opt_dim Dimension. - * @todo stability experimental - */ -ol.geom2.LineStringCollection = function(buf, opt_ranges, opt_dim) { - - /** - * @type {ol.structs.Buffer} - */ - this.buf = buf; - - /** - * @type {Object.} - */ - this.ranges = goog.isDef(opt_ranges) ? opt_ranges : {}; - - /** - * @type {number} - */ - this.dim = goog.isDef(opt_dim) ? opt_dim : 2; - -}; - - -/** - * @param {number} capacity Capacity. - * @param {number=} opt_dim Dimension. - * @return {ol.geom2.LineStringCollection} Line string collection. - */ -ol.geom2.LineStringCollection.createEmpty = function(capacity, opt_dim) { - var dim = goog.isDef(opt_dim) ? opt_dim : 2; - var buf = new ol.structs.Buffer(new Array(capacity * dim), 0); - return new ol.geom2.LineStringCollection(buf, undefined, dim); -}; - - -/** - * This is an internal function that will be removed from the API. - * @param {Array.} unpackedLineStrings Unpacked line - * strings. - * @param {number=} opt_capacity Capacity. - * @param {number=} opt_dim Dimension. - * @return {ol.geom2.LineStringCollection} Line string collection. - * @todo stability experimental - */ -ol.geom2.LineStringCollection.pack = - function(unpackedLineStrings, opt_capacity, opt_dim) { - var i; - var n = unpackedLineStrings.length; - var dim = goog.isDef(opt_dim) ? opt_dim : - n > 0 ? unpackedLineStrings[0][0].length : 2; - var capacity; - if (goog.isDef(opt_capacity)) { - capacity = opt_capacity; - } else { - capacity = 0; - for (i = 0; i < n; ++i) { - capacity += unpackedLineStrings[i].length; - } - } - capacity *= dim; - var arr = new Array(capacity); - /** @type {Object.} */ - var ranges = {}; - var offset = 0; - var start; - for (i = 0; i < n; ++i) { - goog.asserts.assert(unpackedLineStrings[i].length > 1); - start = offset; - offset = ol.geom2.packPoints(arr, offset, unpackedLineStrings[i], dim); - ranges[start + ''] = offset; - } - goog.asserts.assert(offset <= capacity); - var buf = new ol.structs.Buffer(arr, offset); - return new ol.geom2.LineStringCollection(buf, ranges, dim); -}; - - -/** - * @param {ol.geom2.LineString} lineString Line string. - * @return {number} Offset. - */ -ol.geom2.LineStringCollection.prototype.add = function(lineString) { - var n = lineString.length * this.dim; - var offset = this.buf.allocate(n); - goog.asserts.assert(offset != -1); - this.ranges[offset + ''] = offset + n; - ol.geom2.packPoints(this.buf.getArray(), offset, lineString, this.dim); - return offset; -}; - - -/** - * @param {number} offset Offset. - * @return {ol.geom2.LineString} Line string. - */ -ol.geom2.LineStringCollection.prototype.get = function(offset) { - goog.asserts.assert(offset in this.ranges); - var range = this.ranges[offset + '']; - return ol.geom2.unpackPoints( - this.buf.getArray(), offset, range, this.dim); -}; - - -/** - * @return {number} Count. - */ -ol.geom2.LineStringCollection.prototype.getCount = function() { - return goog.object.getCount(this.ranges); -}; - - -/** - * @return {ol.Extent} Extent. - */ -ol.geom2.LineStringCollection.prototype.getExtent = function() { - return ol.geom2.getExtent(this.buf, this.dim); -}; - - -/** - * @return {Uint16Array} Indices. - */ -ol.geom2.LineStringCollection.prototype.getIndices = function() { - // FIXME cache and track dirty / track output length - var dim = this.dim; - var offsets = goog.array.map(goog.object.getKeys(this.ranges), Number); - goog.array.sort(offsets); - var n = offsets.length; - var indices = []; - var i, j, range, offset, stop; - for (i = 0; i < n; ++i) { - offset = offsets[i]; - range = this.ranges[offset]; - stop = range / dim - 1; - for (j = offset / dim; j < stop; ++j) { - indices.push(j, j + 1); - } - } - return new Uint16Array(indices); -}; - - -/** - * @param {number} offset Offset. - */ -ol.geom2.LineStringCollection.prototype.remove = function(offset) { - goog.asserts.assert(offset in this.ranges); - var range = this.ranges[offset + '']; - this.buf.remove(range - offset, offset); - delete this.ranges[offset + '']; -}; - - -/** - * @param {number} offset Offset. - * @param {ol.geom2.LineString} lineString Line string. - * @return {number} Offset. - */ -ol.geom2.LineStringCollection.prototype.set = function(offset, lineString) { - var dim = this.dim; - goog.asserts.assert(offset in this.ranges); - var range = this.ranges[offset + '']; - if (lineString.length * dim == range - offset) { - ol.geom2.packPoints(this.buf.getArray(), offset, lineString, dim); - this.buf.markDirty(range - offset, offset); - return offset; - } else { - this.remove(offset); - return this.add(lineString); - } -}; - - -/** - * @return {Array.} Line strings. - */ -ol.geom2.LineStringCollection.prototype.unpack = function() { - var dim = this.dim; - var n = this.getCount(); - var lineStrings = new Array(n); - var i = 0; - var offset, range; - for (offset in this.ranges) { - range = this.ranges[offset]; - lineStrings[i++] = ol.geom2.unpackPoints( - this.buf.getArray(), Number(offset), range, dim); - } - return lineStrings; -}; diff --git a/src/ol/geom2/pointcollection.exports b/src/ol/geom2/pointcollection.exports deleted file mode 100644 index 7a7a485279..0000000000 --- a/src/ol/geom2/pointcollection.exports +++ /dev/null @@ -1,4 +0,0 @@ -@exportSymbol ol.geom2.PointCollection -@exportSymbol ol.geom2.PointCollection.createEmpty -@exportSymbol ol.geom2.PointCollection.pack -@exportProperty ol.geom2.PointCollection.prototype.add diff --git a/src/ol/geom2/pointcollection.js b/src/ol/geom2/pointcollection.js deleted file mode 100644 index 235fd6b7ab..0000000000 --- a/src/ol/geom2/pointcollection.js +++ /dev/null @@ -1,149 +0,0 @@ -goog.provide('ol.geom2.Point'); -goog.provide('ol.geom2.PointCollection'); - -goog.require('goog.asserts'); -goog.require('ol.Extent'); -goog.require('ol.geom2'); -goog.require('ol.structs.Buffer'); - - -/** - * @typedef {Array.} - */ -ol.geom2.Point; - - - -/** - * This is an internal class that will be removed from the API. - * @constructor - * @param {ol.structs.Buffer} buf Buffer. - * @param {number=} opt_dim Dimension. - * @todo stability experimental - */ -ol.geom2.PointCollection = function(buf, opt_dim) { - - /** - * @type {ol.structs.Buffer} - */ - this.buf = buf; - - /** - * @type {number} - */ - this.dim = goog.isDef(opt_dim) ? opt_dim : 2; - -}; - - -/** - * This is an internal function that will be removed from the API. - * @param {number} capacity Capacity. - * @param {number=} opt_dim Dimension. - * @return {ol.geom2.PointCollection} Point collection. - * @todo stability experimental - */ -ol.geom2.PointCollection.createEmpty = function(capacity, opt_dim) { - var dim = goog.isDef(opt_dim) ? opt_dim : 2; - var buf = new ol.structs.Buffer(new Array(capacity * dim), 0); - return new ol.geom2.PointCollection(buf, dim); -}; - - -/** - * This is an internal function that will be removed from the API. - * @param {Array.} unpackedPoints Unpacked points. - * @param {number=} opt_capacity Capacity. - * @param {number=} opt_dim Dimension. - * @return {ol.geom2.PointCollection} Point collection. - * @todo stability experimental - */ -ol.geom2.PointCollection.pack = - function(unpackedPoints, opt_capacity, opt_dim) { - var n = unpackedPoints.length; - var dim = goog.isDef(opt_dim) ? opt_dim : - n > 0 ? unpackedPoints[0].length : 2; - var capacity = goog.isDef(opt_capacity) ? opt_capacity : n * dim; - goog.asserts.assert(capacity >= n * dim); - var arr = new Array(capacity); - ol.geom2.packPoints(arr, 0, unpackedPoints, dim); - var buf = new ol.structs.Buffer(arr, n * dim); - return new ol.geom2.PointCollection(buf, dim); -}; - - -/** - * @param {ol.geom2.Point} point Point. - * @return {number} Offset. - * @todo stability experimental - */ -ol.geom2.PointCollection.prototype.add = function(point) { - goog.asserts.assert(point.length == this.dim); - return this.buf.add(point); -}; - - -/** - * @param {number} offset Offset. - * @return {ol.geom2.Point} Point. - */ -ol.geom2.PointCollection.prototype.get = function(offset) { - var arr = this.buf.getArray(); - var dim = this.dim; - goog.asserts.assert(0 <= offset && offset + dim < arr.length); - goog.asserts.assert(offset % dim === 0); - return arr.slice(offset, offset + dim); -}; - - -/** - * @return {number} Count. - */ -ol.geom2.PointCollection.prototype.getCount = function() { - return this.buf.getCount() / this.dim; -}; - - -/** - * @return {ol.Extent} Extent. - */ -ol.geom2.PointCollection.prototype.getExtent = function() { - return ol.geom2.getExtent(this.buf, this.dim); -}; - - -/** - * @param {number} offset Offset. - */ -ol.geom2.PointCollection.prototype.remove = function(offset) { - this.buf.remove(this.dim, offset); -}; - - -/** - * @param {number} offset Offset. - * @param {ol.geom2.Point} point Point. - */ -ol.geom2.PointCollection.prototype.set = function(offset, point) { - this.buf.set(point, offset); -}; - - -/** - * @return {Array.} Points. - */ -ol.geom2.PointCollection.prototype.unpack = function() { - var dim = this.dim; - var n = this.getCount(); - var points = new Array(n); - var i = 0; - var bufArr = this.buf.getArray(); - this.buf.forEachRange(function(start, stop) { - var j; - for (j = start; j < stop; j += dim) { - points[i++] = bufArr.slice(j, j + dim); - } - }); - goog.asserts.assert(i == n); - return points; -}; diff --git a/test/spec/ol/geom2/geom2.test.js b/test/spec/ol/geom2/geom2.test.js deleted file mode 100644 index 83e87e7ce8..0000000000 --- a/test/spec/ol/geom2/geom2.test.js +++ /dev/null @@ -1,56 +0,0 @@ -goog.provide('ol.test.geom2'); - - -describe('ol.geom2', function() { - - var buf, dim; - beforeEach(function() { - buf = new ol.structs.Buffer([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 12); - dim = 2; - }); - - describe('ol.geom2.getExtent', function() { - - it('returns the expected extent', function() { - var extent = ol.geom2.getExtent(buf, dim); - expect(extent).to.eql([0, 1, 10, 11]); - }); - - }); - - describe('ol.geom2.packPoints', function() { - - it('packs points as expected', function() { - var arr = []; - var offset = ol.geom2.packPoints(arr, 0, [[0, 1], [2, 3], [4, 5]], 2); - expect(offset).to.be(6); - expect(arr).to.eql([0, 1, 2, 3, 4, 5]); - }); - - it('raises an exception if dimensions do not match', function() { - expect(function() { - ol.geom2.packPoints([], 0, [[0, 1, 2]], 2); - }).to.throwException(); - }); - - }); - - describe('ol.geom2.unpackPoints', function() { - - it('unpacks points in two dimensions', function() { - var unpackedPoints = ol.geom2.unpackPoints([0, 1, 2, 3, 4, 5], 0, 6, 2); - expect(unpackedPoints).to.eql([[0, 1], [2, 3], [4, 5]]); - }); - - it('unpacks points in three dimensions', function() { - var unpackedPoints = ol.geom2.unpackPoints([0, 1, 2, 3, 4, 5], 0, 6, 3); - expect(unpackedPoints).to.eql([[0, 1, 2], [3, 4, 5]]); - }); - - }); - -}); - - -goog.require('ol.geom2'); -goog.require('ol.structs.Buffer'); diff --git a/test/spec/ol/geom2/linecollection.test.js b/test/spec/ol/geom2/linecollection.test.js deleted file mode 100644 index e1a86b7f9f..0000000000 --- a/test/spec/ol/geom2/linecollection.test.js +++ /dev/null @@ -1,330 +0,0 @@ -goog.provide('ol.test.geom2.LineStringCollection'); - - -describe('ol.geom2.LineStringCollection', function() { - - describe('createEmpty', function() { - - it('creates an empty instance with the specified capacity', function() { - var lsc = ol.geom2.LineStringCollection.createEmpty(16); - expect(lsc.getCount()).to.be(0); - expect(lsc.buf.getArray()).to.have.length(32); - }); - - it('can create empty collections for higher dimensions', function() { - var lsc = ol.geom2.LineStringCollection.createEmpty(16, 3); - expect(lsc.getCount()).to.be(0); - expect(lsc.buf.getArray()).to.have.length(48); - }); - - }); - - describe('pack', function() { - - it('packs an empty array', function() { - var lsc = ol.geom2.LineStringCollection.pack([]); - expect(lsc.buf.getArray()).to.be.empty(); - expect(lsc.ranges).to.be.empty(); - expect(lsc.dim).to.be(2); - }); - - it('packs an empty array with a capacity', function() { - var lsc = ol.geom2.LineStringCollection.pack([], 4); - expect(lsc.buf.getArray()).to.eql( - [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]); - expect(lsc.ranges).to.be.empty(); - expect(lsc.dim).to.be(2); - }); - - it('packs an array of line strings', function() { - var lsc = ol.geom2.LineStringCollection.pack( - [[[0, 1], [2, 3], [4, 5]], [[6, 7], [8, 9]]]); - expect(lsc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - expect(lsc.getCount()).to.be(2); - expect(lsc.ranges[0]).to.be(6); - expect(lsc.ranges[6]).to.be(10); - expect(lsc.dim).to.be(2); - }); - - it('packs an array of line strings with a different dimension', function() { - var lsc = ol.geom2.LineStringCollection.pack( - [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]); - expect(lsc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); - expect(lsc.getCount()).to.be(2); - expect(lsc.ranges[0]).to.be(6); - expect(lsc.ranges[6]).to.be(12); - expect(lsc.dim).to.be(3); - }); - - it('packs an array of line strings with extra capacity', function() { - var lsc = ol.geom2.LineStringCollection.pack( - [[[0, 1], [2, 3], [4, 5]], [[6, 7], [8, 9]]], 16); - expect(lsc.buf.getArray().slice(0, 10)).to.eql( - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - expect(lsc.buf.getArray()).to.have.length(32); - expect(lsc.getCount()).to.be(2); - expect(lsc.ranges[0]).to.be(6); - expect(lsc.ranges[6]).to.be(10); - expect(lsc.dim).to.be(2); - }); - - it('throws an error when dimensions are inconsistent', function() { - expect(function() { - var lsc = ol.geom2.LineStringCollection.pack([[[0, 1], [2, 3, 4]]]); - lsc = lsc; // suppress gjslint warning about unused variable - }).to.throwException(); - }); - - it('throws an error when a line string is too short', function() { - expect(function() { - var lsc = ol.geom2.LineStringCollection.pack([[[0, 1]]]); - lsc = lsc; // suppress gjslint warning about unused variable - }).to.throwException(); - }); - - it('throws an error when the capacity is too small', function() { - expect(function() { - var lsc = ol.geom2.LineStringCollection.pack( - [[[0, 1], [2, 3], [4, 5]], [[6, 7], [8, 9]]], 4); - lsc = lsc; // suppress gjslint warning about unused variable - }).to.throwException(); - }); - - }); - - describe('with an empty instance with spare capacity', function() { - - var lsc; - beforeEach(function() { - var buf = new ol.structs.Buffer(new Array(8), 0); - lsc = new ol.geom2.LineStringCollection(buf); - }); - - describe('add', function() { - - it('adds a line string', function() { - var offset = lsc.add([[0, 1], [2, 3]]); - expect(offset).to.be(0); - expect(lsc.getCount()).to.be(1); - expect(lsc.ranges[0]).to.be(4); - expect(lsc.dim).to.be(2); - }); - - }); - - describe('getCount', function() { - - it('returns zero', function() { - expect(lsc.getCount()).to.be(0); - }); - - }); - - describe('getExtent', function() { - - it('returns an empty extent', function() { - expect(ol.extent.isEmpty(lsc.getExtent())).to.be(true); - }); - - }); - - describe('getIndices', function() { - - it('returns the expected value', function() { - expect(lsc.getIndices()).to.be.empty(); - }); - - }); - - describe('remove', function() { - - it('throws an exception', function() { - expect(function() { - lsc.remove(0); - }).to.throwException(); - }); - - }); - - }); - - describe('with an initial line string', function() { - - var lsc, offset; - beforeEach(function() { - var buf = new ol.structs.Buffer(new Array(8), 0); - lsc = new ol.geom2.LineStringCollection(buf); - offset = lsc.add([[0, 1], [2, 3]]); - }); - - describe('add', function() { - - it('can add a second line string', function() { - var offset2 = lsc.add([[4, 5], [6, 7]]); - expect(offset2).to.be(4); - expect(lsc.getCount()).to.be(2); - expect(lsc.ranges[0]).to.be(4); - expect(lsc.ranges[4]).to.be(8); - expect(lsc.dim).to.be(2); - }); - - }); - - describe('get', function() { - - it('returns the expected line string', function() { - expect(lsc.get(0)).to.eql([[0, 1], [2, 3]]); - }); - - }); - - describe('getCount', function() { - - it('returns the expected value', function() { - expect(lsc.getCount()).to.be(1); - }); - - }); - - describe('getExtent', function() { - - it('returns the expected extent', function() { - expect(lsc.getExtent()).to.eql([0, 1, 2, 3]); - }); - - }); - - describe('getIndices', function() { - - it('returns the expected value', function() { - expect(lsc.getIndices()).to.arreql([0, 1]); - }); - - }); - - describe('remove', function() { - - it('removes the line string', function() { - lsc.remove(0); - expect(lsc.getCount()).to.be(0); - }); - - }); - - describe('set', function() { - - it('can update the line string in place', function() { - expect(lsc.set(0, [[4, 5], [6, 7]])).to.be(0); - expect(lsc.buf.getArray()).to.eql([4, 5, 6, 7, NaN, NaN, NaN, NaN]); - }); - - it('can replace the line string with a shorter one', function() { - expect(lsc.set(0, [[4, 5]])).to.be(0); - expect(lsc.buf.getArray()).to.eql([4, 5, NaN, NaN, NaN, NaN, NaN, NaN]); - }); - - it('can replace the line string with a longer one', function() { - expect(lsc.set(0, [[4, 5], [6, 7], [8, 9], [10, 11]])).to.be(0); - expect(lsc.buf.getArray()).to.eql([4, 5, 6, 7, 8, 9, 10, 11]); - }); - - }); - - describe('unpack', function() { - - it('returns the expected value', function() { - expect(lsc.unpack()).to.eql([[[0, 1], [2, 3]]]); - }); - - }); - - }); - - describe('with multiple initial line strings', function() { - - var lsc; - beforeEach(function() { - lsc = ol.geom2.LineStringCollection.pack( - [[[0, 1], [2, 3]], [[4, 5], [6, 7], [8, 9]]], 16); - }); - - describe('get', function() { - - it('returns the expected values', function() { - expect(lsc.get(0)).to.eql([[0, 1], [2, 3]]); - expect(lsc.get(4)).to.eql([[4, 5], [6, 7], [8, 9]]); - }); - - }); - - describe('getCount', function() { - - it('returns the expected value', function() { - expect(lsc.getCount()).to.be(2); - }); - - }); - - describe('getExtent', function() { - - it('returns the expected value', function() { - expect(lsc.getExtent()).to.eql([0, 1, 8, 9]); - }); - - }); - - describe('getIndices', function() { - - it('returns the expected value', function() { - expect(lsc.getIndices()).to.arreql([0, 1, 2, 3, 3, 4]); - }); - - }); - - describe('remove', function() { - - it('can remove the first line string', function() { - lsc.remove(0); - expect(lsc.getCount()).to.be(1); - expect(lsc.get(4)).to.eql([[4, 5], [6, 7], [8, 9]]); - expect(lsc.getIndices()).to.arreql([2, 3, 3, 4]); - }); - - it('can remove the second line string', function() { - lsc.remove(4); - expect(lsc.getCount()).to.be(1); - expect(lsc.get(0)).to.eql([[0, 1], [2, 3]]); - expect(lsc.getIndices()).to.arreql([0, 1]); - }); - - }); - - describe('usage examples', function() { - - it('allows the first line string to be replaced', function() { - lsc.remove(0); - expect(lsc.getCount()).to.be(1); - expect(lsc.add([[10, 11], [12, 13]])).to.be(0); - expect(lsc.getCount()).to.be(2); - expect(lsc.get(0)).to.eql([[10, 11], [12, 13]]); - }); - - it('will allocate at the end of the array', function() { - lsc.remove(0); - expect(lsc.getCount()).to.be(1); - expect(lsc.add([[10, 11], [12, 13], [14, 15]])).to.be(10); - expect(lsc.getCount()).to.be(2); - expect(lsc.get(10)).to.eql([[10, 11], [12, 13], [14, 15]]); - expect(lsc.getIndices()).to.arreql([2, 3, 3, 4, 5, 6, 6, 7]); - }); - - }); - - }); - -}); - - -goog.require('ol.geom2.LineStringCollection'); -goog.require('ol.extent'); -goog.require('ol.structs.Buffer'); diff --git a/test/spec/ol/geom2/pointcollection.test.js b/test/spec/ol/geom2/pointcollection.test.js deleted file mode 100644 index 246dfec466..0000000000 --- a/test/spec/ol/geom2/pointcollection.test.js +++ /dev/null @@ -1,293 +0,0 @@ -goog.provide('ol.test.geom2.PointCollection'); - - -describe('ol.geom2.PointCollection', function() { - - describe('createEmpty', function() { - - it('creates an empty instance with the specified capacity', function() { - var pc = ol.geom2.PointCollection.createEmpty(16); - expect(pc.getCount()).to.be(0); - expect(pc.buf.getArray()).to.have.length(32); - }); - - it('can create empty collections for higher dimensions', function() { - var pc = ol.geom2.PointCollection.createEmpty(16, 3); - expect(pc.getCount()).to.be(0); - expect(pc.buf.getArray()).to.have.length(48); - }); - - }); - - describe('pack', function() { - - it('packs an empty array', function() { - var pc = ol.geom2.PointCollection.pack([]); - expect(pc.buf.getArray()).to.be.empty(); - expect(pc.dim).to.be(2); - }); - - it('packs an empty array with a capacity', function() { - var pc = ol.geom2.PointCollection.pack([], 4); - expect(pc.buf.getArray()).to.eql([NaN, NaN, NaN, NaN]); - expect(pc.dim).to.be(2); - }); - - it('packs an empty array with a capacity and a dimension', function() { - var pc = ol.geom2.PointCollection.pack([], 8, 2); - expect(pc.buf.getArray()).to.eql( - [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]); - expect(pc.dim).to.be(2); - }); - - it('packs a single point', function() { - var pc = ol.geom2.PointCollection.pack([[0, 1]]); - expect(pc.buf.getArray()).to.eql([0, 1]); - expect(pc.dim).to.be(2); - }); - - it('can pack multiple points', function() { - var pc = ol.geom2.PointCollection.pack([[0, 1], [2, 3], [4, 5]]); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5]); - expect(pc.dim).to.be(2); - }); - - it('can pack multiple points with a capacity', function() { - var pc = ol.geom2.PointCollection.pack([[0, 1], [2, 3], [4, 5]], 8); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5, NaN, NaN]); - expect(pc.dim).to.be(2); - }); - - it('can pack a single 3-dimensional point', function() { - var pc = ol.geom2.PointCollection.pack([[0, 1, 2]]); - expect(pc.buf.getArray()).to.eql([0, 1, 2]); - expect(pc.dim).to.be(3); - }); - - it('can pack a multiple 3-dimensional points', function() { - var pc = ol.geom2.PointCollection.pack([[0, 1, 2], [4, 5, 6]]); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 4, 5, 6]); - expect(pc.dim).to.be(3); - }); - - it('raises an error when not all points have the same dimension', - function() { - expect(function() { - var pc = ol.geom2.PointCollection.pack([[0, 1], [2]]); - pc = pc; // suppress gjslint warning about unused variable - }).to.throwException(); - }); - - it('raises an error when the capacity is too small', function() { - expect(function() { - var pc = ol.geom2.PointCollection.pack([[0, 1], [2, 3], [4, 5]], 2); - pc = pc; // suppress gjslint warning about unused variable - }).to.throwException(); - }); - - }); - - describe('with an empty buffer, with capacity for two points', function() { - - var pc; - beforeEach(function() { - var buf = new ol.structs.Buffer(new Array(4), 0); - pc = new ol.geom2.PointCollection(buf); - }); - - describe('add', function() { - - it('can add a first point', function() { - expect(pc.add([0, 1])).to.be(0); - expect(pc.buf.getArray()).to.eql([0, 1, NaN, NaN]); - }); - - it('can add a second point', function() { - expect(pc.add([0, 1])).to.be(0); - expect(pc.buf.getArray()).to.eql([0, 1, NaN, NaN]); - expect(pc.add([2, 3])).to.be(2); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3]); - }); - - it('raises an error when the third point is added', function() { - expect(pc.add([0, 1])).to.be(0); - expect(pc.buf.getArray()).to.eql([0, 1, NaN, NaN]); - expect(pc.add([2, 3])).to.be(2); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3]); - expect(function() { - pc.add([4, 5]); - }).to.throwException(); - }); - - it('raises an error if a point of the wrong dimension is added', - function() { - expect(function() { - pc.add([0, 1, 2]); - }).to.throwException(); - }); - - }); - - describe('getCount', function() { - - it('returns 0', function() { - expect(pc.getCount()).to.be(0); - }); - - }); - - describe('getExtent', function() { - - it('returns an empty extent', function() { - expect(ol.extent.isEmpty(pc.getExtent())).to.be(true); - }); - - }); - - describe('unpack', function() { - - it('returns an empty array', function() { - expect(pc.unpack()).to.be.empty(); - }); - - }); - - }); - - describe('with a partially populated instance', function() { - - var dirtySet, pc; - beforeEach(function() { - dirtySet = new ol.structs.IntegerSet(); - pc = ol.geom2.PointCollection.pack([[0, 1], [2, 3]], 8); - pc.buf.addDirtySet(dirtySet); - }); - - describe('add', function() { - - it('can add more points', function() { - expect(pc.add([4, 5])).to.be(4); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5, NaN, NaN]); - expect(pc.add([6, 7])).to.be(6); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5, 6, 7]); - }); - - }); - - describe('get', function() { - - it('returns the expected value for the first point', function() { - expect(pc.get(0)).to.eql([0, 1]); - }); - - it('returns the expected value for the second point', function() { - expect(pc.get(2)).to.eql([2, 3]); - }); - - }); - - describe('getCount', function() { - - it('returns the expected value', function() { - expect(pc.getCount()).to.be(2); - }); - - }); - - describe('getExtent', function() { - - it('returns the expected value', function() { - var extent = pc.getExtent(); - expect(extent).to.eql([0, 1, 2, 3]); - }); - - }); - - describe('remove', function() { - - it('can remove the first point', function() { - pc.remove(0); - expect(pc.buf.getArray()).to.eql([NaN, NaN, 2, 3, NaN, NaN, NaN, NaN]); - }); - - it('can remove the second point', function() { - pc.remove(2); - expect(pc.buf.getArray()).to.eql([0, 1, NaN, NaN, NaN, NaN, NaN, NaN]); - }); - - }); - - describe('set', function() { - - it('marks the updated elements as dirty', function() { - pc.set(2, [4, 5]); - expect(pc.buf.getArray()).to.eql([0, 1, 4, 5, NaN, NaN, NaN, NaN]); - expect(dirtySet.getArray()).to.eql([2, 4]); - }); - - }); - - describe('unpack', function() { - - it('returns the expect value', function() { - expect(pc.unpack()).to.eql([[0, 1], [2, 3]]); - }); - - }); - - describe('after removing the first point', function() { - - beforeEach(function() { - pc.remove(0); - }); - - describe('getCount', function() { - - it('returns the expected value', function() { - expect(pc.getCount()).to.be(1); - }); - - }); - - describe('unpack', function() { - - it('returns the expected value', function() { - expect(pc.unpack()).to.eql([[2, 3]]); - }); - - }); - - }); - - }); - - describe('usage example', function() { - - it('works as expected', function() { - var pc = ol.geom2.PointCollection.pack([[0, 1], [2, 3], [4, 5]], 8); - var dirtySet = new ol.structs.IntegerSet(); - pc.buf.addDirtySet(dirtySet); - expect(pc.buf.getArray()).to.eql([0, 1, 2, 3, 4, 5, NaN, NaN]); - expect(pc.unpack()).to.have.length(3); - expect(pc.getCount()).to.be(3); - expect(pc.get(2)).to.eql([2, 3]); - pc.remove(2); - expect(pc.buf.getArray()).to.eql([0, 1, NaN, NaN, 4, 5, NaN, NaN]); - expect(pc.unpack()).to.have.length(2); - expect(pc.getCount()).to.be(2); - expect(pc.add([6, 7])).to.be(2); - expect(pc.buf.getArray()).to.eql([0, 1, 6, 7, 4, 5, NaN, NaN]); - expect(pc.unpack()).to.have.length(3); - expect(pc.getCount()).to.be(3); - expect(dirtySet.getArray()).to.eql([2, 4]); - }); - - }); - -}); - - -goog.require('ol.geom2.PointCollection'); -goog.require('ol.extent'); -goog.require('ol.structs.Buffer'); -goog.require('ol.structs.IntegerSet');