Merge pull request #1560 from twpayne/hide-oriented-rings
Hide oriented rings
This commit is contained in:
@@ -73,19 +73,23 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
it('has the expected rings', function() {
|
||||
var linearRings = polygon.getLinearRings();
|
||||
expect(linearRings).to.be.an(Array);
|
||||
expect(linearRings).to.have.length(2);
|
||||
expect(linearRings[0]).to.be.an(ol.geom.LinearRing);
|
||||
expect(linearRings[0].getCoordinates()).to.eql(outerRing);
|
||||
expect(linearRings[1]).to.be.an(ol.geom.LinearRing);
|
||||
expect(linearRings[1].getCoordinates()).to.eql(innerRing);
|
||||
});
|
||||
|
||||
it('reverses inner rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing, innerRing.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses all rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
it('does not reverse any rings', function() {
|
||||
outerRing.reverse();
|
||||
innerRing.reverse();
|
||||
polygon = new ol.geom.Polygon([outerRing, innerRing]);
|
||||
var coordinates = polygon.getCoordinates();
|
||||
expect(coordinates[0]).to.eql(outerRing);
|
||||
expect(coordinates[1]).to.eql(innerRing);
|
||||
});
|
||||
|
||||
it('does not contain outside coordinates', function() {
|
||||
@@ -100,6 +104,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() {
|
||||
@@ -136,21 +163,6 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses inner rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing, innerRing.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses all rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('does not contain outside coordinates', function() {
|
||||
expect(polygon.containsCoordinate(outsideOuter)).to.be(false);
|
||||
});
|
||||
@@ -163,6 +175,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() {
|
||||
@@ -200,21 +235,6 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses inner rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing, innerRing.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses all rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('does not contain outside coordinates', function() {
|
||||
expect(polygon.containsCoordinate(outsideOuter)).to.be(false);
|
||||
});
|
||||
@@ -227,6 +247,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() {
|
||||
@@ -271,24 +314,6 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.getStride()).to.be(4);
|
||||
});
|
||||
|
||||
it('reverses the outer ring if necessary', function() {
|
||||
polygon = new ol.geom.Polygon(
|
||||
[outerRing.reverse(), innerRing1, innerRing2]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses inner rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon(
|
||||
[outerRing, innerRing1.reverse(), innerRing2.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('reverses all rings if necessary', function() {
|
||||
polygon = new ol.geom.Polygon(
|
||||
[outerRing.reverse(), innerRing1.reverse(), innerRing2.reverse()]);
|
||||
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
|
||||
});
|
||||
|
||||
it('does not contain outside coordinates', function() {
|
||||
expect(polygon.containsCoordinate(outsideOuter)).to.be(false);
|
||||
});
|
||||
@@ -302,6 +327,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() {
|
||||
@@ -337,4 +387,5 @@ describe('ol.geom.Polygon', function() {
|
||||
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
@@ -314,9 +314,8 @@ describe('ol.interaction.Draw', function() {
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.Polygon);
|
||||
|
||||
// note that order is forced clockwise (despite drawing counter-clockwise)
|
||||
expect(geometry.getCoordinates()).to.eql([
|
||||
[[10, -20], [30, -10], [30, -20], [10, -20]]
|
||||
[[10, -20], [30, -20], [30, -10], [10, -20]]
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -397,9 +396,8 @@ describe('ol.interaction.Draw', function() {
|
||||
var coordinates = geometry.getCoordinates();
|
||||
expect(coordinates).to.have.length(1);
|
||||
|
||||
// note that order is forced clockwise (despite drawing counter-clockwise)
|
||||
expect(coordinates[0]).to.eql([
|
||||
[[10, -20], [30, -10], [30, -20], [10, -20]]
|
||||
[[10, -20], [30, -20], [30, -10], [10, -20]]
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user