Point, linestring, and linearring coordinates as Float32Array

This commit is contained in:
Tim Schaub
2013-01-18 15:57:48 -07:00
parent 278d32061f
commit fd0a5f3622
13 changed files with 372 additions and 18 deletions

View File

@@ -80,6 +80,10 @@
<script type="text/javascript" src="spec/ol/rectangle.test.js"></script>
<script type="text/javascript" src="spec/ol/resolutionconstraint.test.js"></script>
<script type="text/javascript" src="spec/ol/view2d.test.js"></script>
<script type="text/javascript" src="spec/ol/geom/linearring.test.js"></script>
<script type="text/javascript" src="spec/ol/geom/linestring.test.js"></script>
<script type="text/javascript" src="spec/ol/geom/point.test.js"></script>
<script type="text/javascript" src="spec/ol/geom/polygon.test.js"></script>
<script type="text/javascript" src="spec/ol/layer/layer.test.js"></script>
<script type="text/javascript" src="spec/ol/source/xyz.test.js"></script>
<script type="text/javascript" src="spec/ol/tilecoord.test.js"></script>

View File

@@ -0,0 +1,49 @@
describe('ol.geom.LinearRing', function() {
describe('constructor', function() {
it('creates a ring from an array', function() {
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
expect(ring).toBeA(ol.geom.LinearRing);
});
it('throws when given mismatched dimension', function() {
expect(function() {
var ring = new ol.geom.LinearRing([[10, 20], [30, 40, 50]]);
}).toThrow();
});
});
describe('coordinates', function() {
it('is a Float32Array', function() {
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
expect(ring.coordinates).toBeA(Float32Array);
expect(ring.coordinates.length).toBe(4);
expect(ring.coordinates[0]).toBe(10);
expect(ring.coordinates[1]).toBe(20);
expect(ring.coordinates[2]).toBe(30);
expect(ring.coordinates[3]).toBe(40);
});
});
describe('dimension', function() {
it('can be 2', function() {
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
expect(ring.dimension).toBe(2);
});
it('can be 3', function() {
var ring = new ol.geom.LinearRing([[10, 20, 30], [40, 50, 60]]);
expect(ring.dimension).toBe(3);
});
});
});

View File

@@ -0,0 +1,49 @@
describe('ol.geom.LineString', function() {
describe('constructor', function() {
it('creates a linestring from an array', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line).toBeA(ol.geom.LineString);
});
it('throws when given mismatched dimension', function() {
expect(function() {
var line = new ol.geom.LineString([[10, 20], [30, 40, 50]]);
}).toThrow();
});
});
describe('coordinates', function() {
it('is a Float32Array', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.coordinates).toBeA(Float32Array);
expect(line.coordinates.length).toBe(4);
expect(line.coordinates[0]).toBe(10);
expect(line.coordinates[1]).toBe(20);
expect(line.coordinates[2]).toBe(30);
expect(line.coordinates[3]).toBe(40);
});
});
describe('dimension', function() {
it('can be 2', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.dimension).toBe(2);
});
it('can be 3', function() {
var line = new ol.geom.LineString([[10, 20, 30], [40, 50, 60]]);
expect(line.dimension).toBe(3);
});
});
});

View File

@@ -0,0 +1,48 @@
describe('ol.geom.Point', function() {
describe('constructor', function() {
it('creates a point from an array', function() {
var point = new ol.geom.Point([10, 20]);
expect(point).toBeA(ol.geom.Point);
});
it('throws when given with insufficient dimensions', function() {
expect(function() {
var point = new ol.geom.Point([1]);
}).toThrow();
});
});
describe('coordinates', function() {
it('is a Float32Array', function() {
var point = new ol.geom.Point([10, 20]);
expect(point.coordinates).toBeA(Float32Array);
expect(point.coordinates.length).toBe(2);
expect(point.coordinates[0]).toBe(10);
expect(point.coordinates[1]).toBe(20);
});
});
describe('dimension', function() {
it('can be 2', function() {
var point = new ol.geom.Point([10, 20]);
expect(point.dimension).toBe(2);
});
it('can be 3', function() {
var point = new ol.geom.Point([10, 20, 30]);
expect(point.dimension).toBe(3);
});
});
});

View File

@@ -0,0 +1,51 @@
describe('ol.geom.Polygon', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
describe('constructor', function() {
it('creates a polygon from an array', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
expect(poly).toBeA(ol.geom.Polygon);
});
it('throws when given mismatched dimension', function() {
expect(function() {
var poly = new ol.geom.Polygon([[[10, 20], [30, 40, 50]]]);
}).toThrow();
});
});
describe('rings', function() {
it('is an array of LinearRing', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
expect(poly.rings.length).toBe(3);
expect(poly.rings[0]).toBeA(ol.geom.LinearRing);
expect(poly.rings[1]).toBeA(ol.geom.LinearRing);
expect(poly.rings[2]).toBeA(ol.geom.LinearRing);
});
});
describe('dimension', function() {
it('can be 2', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
expect(poly.dimension).toBe(2);
});
it('can be 3', function() {
var poly = new ol.geom.Polygon([[[10, 20, 30], [40, 50, 60]]]);
expect(poly.dimension).toBe(3);
});
});
});