Don't automatically orient rings in ol.geom.Polygon

This commit is contained in:
Tom Payne
2014-01-21 07:47:36 +01:00
parent 36387adf3f
commit ff73f080b3
3 changed files with 8 additions and 65 deletions

View File

@@ -192,8 +192,6 @@ ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
var ends = ol.geom.flat.deflateCoordinatess( var ends = ol.geom.flat.deflateCoordinatess(
this.flatCoordinates, 0, coordinates, this.stride, this.ends_); this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1]; this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
ol.geom.flat.orientLinearRings(
this.flatCoordinates, 0, this.ends_, this.stride);
this.dispatchChangeEvent(); this.dispatchChangeEvent();
} }
}; };

View File

@@ -73,19 +73,13 @@ describe('ol.geom.Polygon', function() {
expect(polygon.getStride()).to.be(2); expect(polygon.getStride()).to.be(2);
}); });
it('reverses the outer ring if necessary', function() { it('does not reverse any rings', function() {
polygon = new ol.geom.Polygon([outerRing.reverse(), innerRing]); outerRing.reverse();
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates); innerRing.reverse();
}); polygon = new ol.geom.Polygon([outerRing, innerRing]);
var coordinates = polygon.getCoordinates();
it('reverses inner rings if necessary', function() { expect(coordinates[0]).to.eql(outerRing);
polygon = new ol.geom.Polygon([outerRing, innerRing.reverse()]); expect(coordinates[1]).to.eql(innerRing);
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() { it('does not contain outside coordinates', function() {
@@ -136,21 +130,6 @@ describe('ol.geom.Polygon', function() {
expect(polygon.getStride()).to.be(3); 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() { it('does not contain outside coordinates', function() {
expect(polygon.containsCoordinate(outsideOuter)).to.be(false); expect(polygon.containsCoordinate(outsideOuter)).to.be(false);
}); });
@@ -200,21 +179,6 @@ describe('ol.geom.Polygon', function() {
expect(polygon.getStride()).to.be(3); 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() { it('does not contain outside coordinates', function() {
expect(polygon.containsCoordinate(outsideOuter)).to.be(false); expect(polygon.containsCoordinate(outsideOuter)).to.be(false);
}); });
@@ -271,24 +235,6 @@ describe('ol.geom.Polygon', function() {
expect(polygon.getStride()).to.be(4); 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() { it('does not contain outside coordinates', function() {
expect(polygon.containsCoordinate(outsideOuter)).to.be(false); expect(polygon.containsCoordinate(outsideOuter)).to.be(false);
}); });

View File

@@ -314,9 +314,8 @@ describe('ol.interaction.Draw', function() {
var geometry = features[0].getGeometry(); var geometry = features[0].getGeometry();
expect(geometry).to.be.a(ol.geom.Polygon); expect(geometry).to.be.a(ol.geom.Polygon);
// note that order is forced clockwise (despite drawing counter-clockwise)
expect(geometry.getCoordinates()).to.eql([ expect(geometry.getCoordinates()).to.eql([
[[10, -20], [30, -10], [30, -20], [10, -20]] [[10, -20], [30, -20], [30, -10], [10, -20]]
]); ]);
}); });