Merge pull request #913 from tschaub/dimension
Allow for vector data with unknown or inconsistent dimension.
This commit is contained in:
@@ -71,14 +71,9 @@ ol.geom.SharedVertices.prototype.add = function(vertices) {
|
|||||||
var vertex, index;
|
var vertex, index;
|
||||||
for (var i = 0; i < count; ++i) {
|
for (var i = 0; i < count; ++i) {
|
||||||
vertex = vertices[i];
|
vertex = vertices[i];
|
||||||
goog.asserts.assert(vertex.length == dimension);
|
index = start + (i * dimension);
|
||||||
if (!offset) {
|
for (var j = 0; j < dimension; ++j) {
|
||||||
Array.prototype.push.apply(this.coordinates, vertex);
|
this.coordinates[index + j] = vertex[j] - (offset ? offset[j] : 0);
|
||||||
} else {
|
|
||||||
index = start + (i * dimension);
|
|
||||||
for (var j = 0; j < dimension; ++j) {
|
|
||||||
this.coordinates[index + j] = vertex[j] - offset[j];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var length = this.starts_.push(start);
|
var length = this.starts_.push(start);
|
||||||
|
|||||||
@@ -9,13 +9,6 @@ describe('ol.geom.LinearRing', function() {
|
|||||||
expect(ring).to.be.a(ol.geom.LinearRing);
|
expect(ring).to.be.a(ol.geom.LinearRing);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given mismatched dimension', function() {
|
|
||||||
expect(function() {
|
|
||||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40, 50]]);
|
|
||||||
ring = ring; // suppress gjslint warning about unused variable
|
|
||||||
}).to.throwException();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#dimension', function() {
|
describe('#dimension', function() {
|
||||||
|
|||||||
@@ -10,13 +10,6 @@ describe('ol.geom.LineString', function() {
|
|||||||
expect(line).to.be.a(ol.geom.Geometry);
|
expect(line).to.be.a(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given mismatched dimension', function() {
|
|
||||||
expect(function() {
|
|
||||||
var line = new ol.geom.LineString([[10, 20], [30, 40, 50]]);
|
|
||||||
line = line; // suppress gjslint warning about unused variable
|
|
||||||
}).to.throwException();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('accepts shared vertices', function() {
|
it('accepts shared vertices', function() {
|
||||||
var vertices = new ol.geom.SharedVertices();
|
var vertices = new ol.geom.SharedVertices();
|
||||||
var l1 = new ol.geom.LineString([[10, 20], [30, 40]], vertices);
|
var l1 = new ol.geom.LineString([[10, 20], [30, 40]], vertices);
|
||||||
|
|||||||
@@ -14,13 +14,6 @@ describe('ol.geom.Polygon', function() {
|
|||||||
expect(poly).to.be.a(ol.geom.Geometry);
|
expect(poly).to.be.a(ol.geom.Geometry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when given mismatched dimension', function() {
|
|
||||||
expect(function() {
|
|
||||||
var poly = new ol.geom.Polygon([[[10, 20], [30, 40, 50]]]);
|
|
||||||
poly = poly; // suppress gjslint warning about unused variable
|
|
||||||
}).to.throwException();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('accepts shared vertices', function() {
|
it('accepts shared vertices', function() {
|
||||||
var vertices = new ol.geom.SharedVertices();
|
var vertices = new ol.geom.SharedVertices();
|
||||||
var p1 = new ol.geom.Polygon([outer], vertices);
|
var p1 = new ol.geom.Polygon([outer], vertices);
|
||||||
|
|||||||
@@ -40,6 +40,25 @@ describe('ol.geom.SharedVertices', function() {
|
|||||||
expect(vertices.coordinates).to.eql([1, 2, 3, 4, 5, 6]);
|
expect(vertices.coordinates).to.eql([1, 2, 3, 4, 5, 6]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ignores extra dimensions', function() {
|
||||||
|
var vertices = new ol.geom.SharedVertices({dimension: 2});
|
||||||
|
expect(vertices.coordinates.length).to.be(0);
|
||||||
|
|
||||||
|
vertices.add([[1, 2], [3, 4, 5], [6, 7]]);
|
||||||
|
expect(vertices.coordinates).to.eql([1, 2, 3, 4, 6, 7]);
|
||||||
|
|
||||||
|
vertices.add([[8, 9, 10]]);
|
||||||
|
expect(vertices.coordinates).to.eql([1, 2, 3, 4, 6, 7, 8, 9]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pads with NaN when dimension not provided', function() {
|
||||||
|
var vertices = new ol.geom.SharedVertices({dimension: 3});
|
||||||
|
expect(vertices.coordinates.length).to.be(0);
|
||||||
|
|
||||||
|
vertices.add([[1, 2], [3, 4, 5], [6, 7]]);
|
||||||
|
expect(vertices.coordinates).to.eql([1, 2, NaN, 3, 4, 5, 6, 7, NaN]);
|
||||||
|
});
|
||||||
|
|
||||||
it('returns an identifier for coordinate access', function() {
|
it('returns an identifier for coordinate access', function() {
|
||||||
var vertices = new ol.geom.SharedVertices();
|
var vertices = new ol.geom.SharedVertices();
|
||||||
var id = vertices.add([[1, 2], [3, 4]]);
|
var id = vertices.add([[1, 2], [3, 4]]);
|
||||||
|
|||||||
Reference in New Issue
Block a user