Merge pull request #913 from tschaub/dimension

Allow for vector data with unknown or inconsistent dimension.
This commit is contained in:
Tim Schaub
2013-08-26 05:59:50 -07:00
5 changed files with 22 additions and 29 deletions

View File

@@ -9,13 +9,6 @@ describe('ol.geom.LinearRing', function() {
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() {

View File

@@ -10,13 +10,6 @@ describe('ol.geom.LineString', function() {
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() {
var vertices = new ol.geom.SharedVertices();
var l1 = new ol.geom.LineString([[10, 20], [30, 40]], vertices);

View File

@@ -14,13 +14,6 @@ describe('ol.geom.Polygon', function() {
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() {
var vertices = new ol.geom.SharedVertices();
var p1 = new ol.geom.Polygon([outer], vertices);

View File

@@ -40,6 +40,25 @@ describe('ol.geom.SharedVertices', function() {
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() {
var vertices = new ol.geom.SharedVertices();
var id = vertices.add([[1, 2], [3, 4]]);