Add getBounds to geometry
This commit is contained in:
@@ -15,7 +15,7 @@ describe('ol.geom.LinearRing', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('coordinates', function() {
|
||||
describe('#coordinates', function() {
|
||||
|
||||
it('is a Float64Array', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
@@ -30,7 +30,7 @@ describe('ol.geom.LinearRing', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('dimension', function() {
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('ol.geom.LineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('coordinates', function() {
|
||||
describe('#coordinates', function() {
|
||||
|
||||
it('is a Float64Array', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
@@ -30,7 +30,7 @@ describe('ol.geom.LineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('dimension', function() {
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
@@ -44,6 +44,19 @@ describe('ol.geom.LineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
|
||||
var bounds = line.getBounds();
|
||||
expect(bounds.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(30);
|
||||
expect(bounds.maxY).toBe(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
69
test/spec/ol/geom/multilinestring.test.js
Normal file
69
test/spec/ol/geom/multilinestring.test.js
Normal file
@@ -0,0 +1,69 @@
|
||||
describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-linestring from an array', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
expect(multi).toBeA(ol.geom.MultiLineString);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPoint([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of linestrings', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
|
||||
expect(multi.components.length).toBe(2);
|
||||
expect(multi.components[0]).toBeA(ol.geom.LineString);
|
||||
expect(multi.components[1]).toBeA(ol.geom.LineString);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
expect(multi.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20, 30], [30, 40, 50]],
|
||||
[[20, 30, 40], [40, 50, 60]]]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(40);
|
||||
expect(bounds.maxY).toBe(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
59
test/spec/ol/geom/multipoint.test.js
Normal file
59
test/spec/ol/geom/multipoint.test.js
Normal file
@@ -0,0 +1,59 @@
|
||||
describe('ol.geom.MultiPoint', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-point from an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi).toBeA(ol.geom.MultiPoint);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPoint([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of points', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
|
||||
expect(multi.components.length).toBe(2);
|
||||
expect(multi.components[0]).toBeA(ol.geom.Point);
|
||||
expect(multi.components[1]).toBeA(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20, 30], [30, 40, 50]]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(30);
|
||||
expect(bounds.maxY).toBe(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
72
test/spec/ol/geom/multipolygon.test.js
Normal file
72
test/spec/ol/geom/multipolygon.test.js
Normal file
@@ -0,0 +1,72 @@
|
||||
describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
var outer1 = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1a = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner1b = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]],
|
||||
outer2 = [[10, 10], [20, 0], [20, 50], [10, 50], [10, 10]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-linestring from an array', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
expect(multi).toBeA(ol.geom.MultiPolygon);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPolygon([1]);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of polygons', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
|
||||
expect(multi.components.length).toBe(2);
|
||||
expect(multi.components[0]).toBeA(ol.geom.Polygon);
|
||||
expect(multi.components[1]).toBeA(ol.geom.Polygon);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
expect(multi.dimension).toBe(2);
|
||||
});
|
||||
|
||||
it('can be 3', function() {
|
||||
var multi = new ol.geom.MultiPolygon([[[[10, 20, 30], [40, 50, 60]]]]);
|
||||
expect(multi.dimension).toBe(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds.minX).toBe(0);
|
||||
expect(bounds.minY).toBe(0);
|
||||
expect(bounds.maxX).toBe(20);
|
||||
expect(bounds.maxY).toBe(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('ol.geom.Point', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('coordinates', function() {
|
||||
describe('#coordinates', function() {
|
||||
|
||||
it('is a Float64Array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
@@ -29,7 +29,7 @@ describe('ol.geom.Point', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('dimension', function() {
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
@@ -43,6 +43,18 @@ describe('ol.geom.Point', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var bounds = point.getBounds();
|
||||
expect(bounds.minX).toBe(10);
|
||||
expect(bounds.minY).toBe(20);
|
||||
expect(bounds.maxX).toBe(10);
|
||||
expect(bounds.maxY).toBe(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('ol.geom.Polygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('rings', function() {
|
||||
describe('#rings', function() {
|
||||
|
||||
it('is an array of LinearRing', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
@@ -32,7 +32,7 @@ describe('ol.geom.Polygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('dimension', function() {
|
||||
describe('#dimension', function() {
|
||||
|
||||
it('can be 2', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
@@ -46,6 +46,19 @@ describe('ol.geom.Polygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var bounds = poly.getBounds();
|
||||
expect(bounds.minX).toBe(0);
|
||||
expect(bounds.minY).toBe(0);
|
||||
expect(bounds.maxX).toBe(10);
|
||||
expect(bounds.maxY).toBe(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user