Add ol.geom.Polygon#getOrientedFlatCoordinates

This commit is contained in:
Tom Payne
2014-01-21 07:48:13 +01:00
parent ff73f080b3
commit 5b5865d48e
2 changed files with 126 additions and 0 deletions

View File

@@ -94,6 +94,29 @@ describe('ol.geom.Polygon', function() {
expect(polygon.containsCoordinate(insideInner)).to.be(false);
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
outerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
innerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
outerRing.reverse();
innerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 3D coordinates', function() {
@@ -142,6 +165,29 @@ describe('ol.geom.Polygon', function() {
expect(polygon.containsCoordinate(insideInner)).to.be(false);
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
outerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
innerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
outerRing.reverse();
innerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 3D coordinates and layout XYM', function() {
@@ -191,6 +237,29 @@ describe('ol.geom.Polygon', function() {
expect(polygon.containsCoordinate(insideInner)).to.be(false);
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
outerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
innerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
outerRing.reverse();
innerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 4D coordinates', function() {
@@ -248,6 +317,31 @@ describe('ol.geom.Polygon', function() {
expect(polygon.containsCoordinate(insideInner2)).to.be(false);
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
outerRing.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
innerRing1.reverse();
innerRing2.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
outerRing.reverse();
innerRing1.reverse();
innerRing2.reverse();
polygon = new ol.geom.Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('with a simple polygon', function() {