Add method to determine winding order of linear rings

This commit is contained in:
Tim Schaub
2013-06-24 17:43:22 -06:00
parent d1eec80324
commit e292d8fa12
2 changed files with 71 additions and 0 deletions

View File

@@ -108,4 +108,39 @@ describe('ol.geom.LinearRing', function() {
});
describe('ol.geom.LinearRing.isClockwise()', function() {
var isClockwise = ol.geom.LinearRing.isClockwise;
it('returns true for clockwise coordinates', function() {
var coordinates = [
[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]
];
expect(isClockwise(coordinates)).to.be(true);
});
it('returns false for counter-clockwise coordinates', function() {
var coordinates = [
[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]
];
expect(isClockwise(coordinates)).to.be(false);
});
it('returns true for mostly clockwise, self-intersecting ring', function() {
var coordinates = [
[0, 0], [0, 1], [1.5, 1], [1.5, 1.5], [1, 1.5], [1, 0], [0, 0]
];
expect(isClockwise(coordinates)).to.be(true);
});
it('returns false for mostly counter-clockwise, intersecting', function() {
var coordinates = [
[0, 0], [1, 0], [1, 1.5], [1.5, 1.5], [1.5, 1], [0, 1], [0, 0]
];
expect(isClockwise(coordinates)).to.be(false);
});
});
goog.require('ol.geom.LinearRing');