diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 97393ef2f2..ca9eb29b73 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -16,7 +16,7 @@ import {deflateMultiCoordinatesArray} from './flat/deflate.js'; import {inflateMultiCoordinatesArray} from './flat/inflate.js'; import {getInteriorPointsOfMultiArray} from './flat/interiorpoint.js'; import {intersectsLinearRingMultiArray} from './flat/intersectsextent.js'; -import {linearRingsAreOriented, orientLinearRingsArray} from './flat/orient.js'; +import {linearRingssAreOriented, orientLinearRingsArray} from './flat/orient.js'; import {quantizeMultiArray} from './flat/simplify.js'; /** @@ -251,7 +251,7 @@ class MultiPolygon extends SimpleGeometry { getOrientedFlatCoordinates() { if (this.orientedRevision_ != this.getRevision()) { const flatCoordinates = this.flatCoordinates; - if (linearRingsAreOriented( + if (linearRingssAreOriented( flatCoordinates, 0, this.endss_, this.stride)) { this.orientedFlatCoordinates_ = flatCoordinates; } else { diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index bc240593e1..24d0f17d82 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -16,7 +16,7 @@ import {deflateCoordinatesArray} from './flat/deflate.js'; import {inflateCoordinatesArray} from './flat/inflate.js'; import {getInteriorPointOfArray} from './flat/interiorpoint.js'; import {intersectsLinearRingArray} from './flat/intersectsextent.js'; -import {linearRingIsOriented, orientLinearRings} from './flat/orient.js'; +import {linearRingsAreOriented, orientLinearRings} from './flat/orient.js'; import {quantizeArray} from './flat/simplify.js'; import {modulo} from '../math.js'; @@ -266,7 +266,7 @@ class Polygon extends SimpleGeometry { getOrientedFlatCoordinates() { if (this.orientedRevision_ != this.getRevision()) { const flatCoordinates = this.flatCoordinates; - if (linearRingIsOriented( + if (linearRingsAreOriented( flatCoordinates, 0, this.ends_, this.stride)) { this.orientedFlatCoordinates_ = flatCoordinates; } else { diff --git a/src/ol/geom/flat/orient.js b/src/ol/geom/flat/orient.js index 1ef11c2438..8eb9dd1ab5 100644 --- a/src/ol/geom/flat/orient.js +++ b/src/ol/geom/flat/orient.js @@ -41,7 +41,7 @@ export function linearRingIsClockwise(flatCoordinates, offset, end, stride) { * (counter-clockwise exterior ring and clockwise interior rings). * @return {boolean} Rings are correctly oriented. */ -export function linearRingIsOriented(flatCoordinates, offset, ends, stride, opt_right) { +export function linearRingsAreOriented(flatCoordinates, offset, ends, stride, opt_right) { const right = opt_right !== undefined ? opt_right : false; for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; @@ -75,12 +75,16 @@ export function linearRingIsOriented(flatCoordinates, offset, ends, stride, opt_ * (counter-clockwise exterior ring and clockwise interior rings). * @return {boolean} Rings are correctly oriented. */ -export function linearRingsAreOriented(flatCoordinates, offset, endss, stride, opt_right) { +export function linearRingssAreOriented(flatCoordinates, offset, endss, stride, opt_right) { for (let i = 0, ii = endss.length; i < ii; ++i) { - if (!linearRingIsOriented( - flatCoordinates, offset, endss[i], stride, opt_right)) { + const ends = endss[i]; + if (!linearRingsAreOriented( + flatCoordinates, offset, ends, stride, opt_right)) { return false; } + if (ends.length) { + offset = ends[ends.length - 1]; + } } return true; } diff --git a/test/spec/ol/geom/flat/orient.test.js b/test/spec/ol/geom/flat/orient.test.js index 610e741008..4c2c94ef0c 100644 --- a/test/spec/ol/geom/flat/orient.test.js +++ b/test/spec/ol/geom/flat/orient.test.js @@ -1,5 +1,5 @@ -import {linearRingIsClockwise, linearRingIsOriented, - linearRingsAreOriented, orientLinearRings, orientLinearRingsArray} from '../../../../../src/ol/geom/flat/orient.js'; +import {linearRingIsClockwise, linearRingsAreOriented, + linearRingssAreOriented, orientLinearRings, orientLinearRingsArray} from '../../../../../src/ol/geom/flat/orient.js'; describe('ol.geom.flat.orient', function() { @@ -22,8 +22,8 @@ describe('ol.geom.flat.orient', function() { }); - describe('ol.geom.flat.orient.linearRingIsOriented', function() { - const oriented = linearRingIsOriented; + describe('ol.geom.flat.orient.linearRingsAreOriented', function() { + const oriented = linearRingsAreOriented; const rightCoords = [ -180, -90, 180, -90, 180, 90, -180, 90, -180, -90, @@ -49,8 +49,8 @@ describe('ol.geom.flat.orient', function() { }); - describe('ol.geom.flat.orient.linearRingsAreOriented', function() { - const oriented = linearRingsAreOriented; + describe('ol.geom.flat.orient.linearRingssAreOriented', function() { + const oriented = linearRingssAreOriented; const rightCoords = [ -180, -90, 180, -90, 180, 90, -180, 90, -180, -90, diff --git a/test/spec/ol/geom/multipolygon.test.js b/test/spec/ol/geom/multipolygon.test.js index 8a7f206295..1d76457916 100644 --- a/test/spec/ol/geom/multipolygon.test.js +++ b/test/spec/ol/geom/multipolygon.test.js @@ -188,6 +188,17 @@ describe('ol.geom.MultiPolygon', function() { }); + describe('#getArea', function() { + + it('works with a clockwise and a counterclockwise Polygon', function() { + const multiPolygon = new MultiPolygon([ + [[[1, 3], [1, 2], [0, 2], [1, 3]]], // clockwise polygon with area 0.5 + [[[2, 1], [2, 0.5], [3, 1], [2, 1]]] // counterclockwise polygon with area 0.25 + ]); + expect(multiPolygon.getArea()).to.be(0.75); + }); + }); + describe('#getInteriorPoints', function() { it('returns XYM multipoint with intersection width as M', function() {