Add tests for intersectsExtent/getExtent
This commit adds tests for `intersectsExtent` of Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon and GeometryCollection. It also adds a basic test for `getExtent` of MultiPolygon
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.test.geom.GeometryCollection');
|
||||
|
||||
goog.require('ol.extent');
|
||||
|
||||
describe('ol.geom.GeometryCollection', function() {
|
||||
|
||||
@@ -114,6 +115,35 @@ describe('ol.geom.GeometryCollection', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#intersectsExtent()', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
point = new ol.geom.Point([5, 20]);
|
||||
line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
});
|
||||
|
||||
it('returns true for intersecting point', function() {
|
||||
expect(multi.intersectsExtent([5, 20, 5, 20])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for intersecting part of lineString', function() {
|
||||
expect(multi.intersectsExtent([25, 35, 30, 40])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for intersecting part of polygon', function() {
|
||||
expect(multi.intersectsExtent([0, 0, 5, 5])).to.be(true);
|
||||
});
|
||||
|
||||
|
||||
it('returns false for non-matching extent within own extent', function() {
|
||||
var extent = [0, 35, 5, 40];
|
||||
expect(poly.intersectsExtent(extent)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setGeometries', function() {
|
||||
|
||||
var line, multi, point, poly;
|
||||
|
||||
@@ -73,6 +73,22 @@ describe('ol.geom.LineString', function() {
|
||||
expect(lineString.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('return false for non matching extent', function() {
|
||||
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
|
||||
});
|
||||
|
||||
it('return true for extent on midpoint', function() {
|
||||
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for the geom\'s own extent', function() {
|
||||
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates', function() {
|
||||
@@ -102,6 +118,22 @@ describe('ol.geom.LineString', function() {
|
||||
expect(lineString.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('return false for non matching extent', function() {
|
||||
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
|
||||
});
|
||||
|
||||
it('return true for extent on midpoint', function() {
|
||||
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for the geom\'s own extent', function() {
|
||||
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates and layout XYM', function() {
|
||||
@@ -132,6 +164,22 @@ describe('ol.geom.LineString', function() {
|
||||
expect(lineString.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('return false for non matching extent', function() {
|
||||
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
|
||||
});
|
||||
|
||||
it('return true for extent on midpoint', function() {
|
||||
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for the geom\'s own extent', function() {
|
||||
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 4D coordinates', function() {
|
||||
@@ -161,6 +209,22 @@ describe('ol.geom.LineString', function() {
|
||||
expect(lineString.getStride()).to.be(4);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('return false for non matching extent', function() {
|
||||
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
|
||||
});
|
||||
|
||||
it('return true for extent on midpoint', function() {
|
||||
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true for the geom\'s own extent', function() {
|
||||
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a simple line string', function() {
|
||||
|
||||
@@ -88,6 +88,18 @@ describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#intersectsExtent()', function() {
|
||||
|
||||
it('returns true for intersecting part of lineString', function() {
|
||||
expect(multiLineString.intersectsExtent([1, 2, 2, 3])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for non-matching extent within own extent', function() {
|
||||
expect(multiLineString.intersectsExtent([1, 7, 2, 8])).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates', function() {
|
||||
|
||||
@@ -73,6 +73,18 @@ describe('ol.geom.MultiPoint', function() {
|
||||
expect(multiPoint.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent()', function() {
|
||||
|
||||
it('returns true for extent covering a point', function() {
|
||||
expect(multiPoint.intersectsExtent([1, 2, 2, 2])).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for non-matching extent within own extent', function() {
|
||||
expect(multiPoint.intersectsExtent([2, 3, 2, 4])).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates', function() {
|
||||
|
||||
@@ -115,6 +115,14 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#getExtent()', function() {
|
||||
|
||||
it('returns expected result', function() {
|
||||
expect(multiPolygon.getExtent()).to.eql([0, 0, 5, 2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getSimplifiedGeometry', function() {
|
||||
|
||||
it('returns the expected result', function() {
|
||||
@@ -127,6 +135,22 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#intersectsExtent()', function() {
|
||||
|
||||
it('returns true for extent of of each polygon', function() {
|
||||
var polygons = multiPolygon.getPolygons();
|
||||
for (var i = 0; i < polygons.length; i++) {
|
||||
expect(multiPolygon.intersectsExtent(
|
||||
polygons[i].getExtent())).to.be(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns false for non-matching extent within own extent', function() {
|
||||
expect(multiPolygon.intersectsExtent([2.1, 0, 2.9, 2])).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -37,6 +37,14 @@ describe('ol.geom.Point', function() {
|
||||
expect(point.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('does not intersect non matching extent', function() {
|
||||
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
|
||||
});
|
||||
|
||||
it('does intersect it\'s extent', function() {
|
||||
expect(point.intersectsExtent(point.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates and layout XYM', function() {
|
||||
@@ -66,6 +74,14 @@ describe('ol.geom.Point', function() {
|
||||
expect(point.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('does not intersect non matching extent', function() {
|
||||
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
|
||||
});
|
||||
|
||||
it('does intersect it\'s extent', function() {
|
||||
expect(point.intersectsExtent(point.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 4D coordinates', function() {
|
||||
@@ -95,6 +111,14 @@ describe('ol.geom.Point', function() {
|
||||
expect(point.getStride()).to.be(4);
|
||||
});
|
||||
|
||||
it('does not intersect non matching extent', function() {
|
||||
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
|
||||
});
|
||||
|
||||
it('does intersect it\'s extent', function() {
|
||||
expect(point.intersectsExtent(point.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
describe('#getClosestPoint', function() {
|
||||
|
||||
it('preseves extra dimensions', function() {
|
||||
|
||||
@@ -215,6 +215,33 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.containsCoordinate(insideInner)).to.be(false);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('does not intersect outside extent', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([outsideOuter]))).to.be(false);
|
||||
});
|
||||
|
||||
it('does intersect inside extent', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([inside]))).to.be(true);
|
||||
});
|
||||
|
||||
it('does intersect boundary extent', function() {
|
||||
var firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
|
||||
var firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
|
||||
|
||||
expect(polygon.intersectsExtent(ol.extent.boundingExtent([[firstMidX,
|
||||
firstMidY]]))).to.be(true);
|
||||
});
|
||||
|
||||
it('does not intersect extent fully contained by inner ring', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([insideInner]))).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOrientedFlatCoordinates', function() {
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
@@ -287,6 +314,33 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.containsCoordinate(insideInner)).to.be(false);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('does not intersect outside extent', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([outsideOuter]))).to.be(false);
|
||||
});
|
||||
|
||||
it('does intersect inside extent', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([inside]))).to.be(true);
|
||||
});
|
||||
|
||||
it('does intersect boundary extent', function() {
|
||||
var firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
|
||||
var firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
|
||||
|
||||
expect(polygon.intersectsExtent(ol.extent.boundingExtent([[firstMidX,
|
||||
firstMidY]]))).to.be(true);
|
||||
});
|
||||
|
||||
it('does not intersect extent fully contained by inner ring', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([insideInner]))).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOrientedFlatCoordinates', function() {
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
@@ -367,6 +421,35 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.containsCoordinate(insideInner2)).to.be(false);
|
||||
});
|
||||
|
||||
describe('#intersectsExtent', function() {
|
||||
|
||||
it('does not intersect outside extent', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([outsideOuter]))).to.be(false);
|
||||
});
|
||||
|
||||
it('does intersect inside extent', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([inside]))).to.be(true);
|
||||
});
|
||||
|
||||
it('does intersect boundary extent', function() {
|
||||
var firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
|
||||
var firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
|
||||
|
||||
expect(polygon.intersectsExtent(ol.extent.boundingExtent([[firstMidX,
|
||||
firstMidY]]))).to.be(true);
|
||||
});
|
||||
|
||||
it('does not intersect extent fully contained by inner ring', function() {
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([insideInner1]))).to.be(false);
|
||||
expect(polygon.intersectsExtent(
|
||||
ol.extent.boundingExtent([insideInner2]))).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOrientedFlatCoordinates', function() {
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
|
||||
Reference in New Issue
Block a user