ol/geom/flat/orient export
This commit is contained in:
@@ -17,7 +17,7 @@ import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
||||
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import {assign, isEmpty} from '../obj.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
|
||||
@@ -134,7 +134,7 @@ function convertRings(rings, layout) {
|
||||
flatRing.length = 0;
|
||||
deflateCoordinates(flatRing, 0, rings[i], layout.length);
|
||||
// is this ring an outer ring? is it clockwise?
|
||||
const clockwise = _ol_geom_flat_orient_.linearRingIsClockwise(flatRing, 0,
|
||||
const clockwise = linearRingIsClockwise(flatRing, 0,
|
||||
flatRing.length, layout.length);
|
||||
if (clockwise) {
|
||||
outerRings.push([rings[i]]);
|
||||
|
||||
@@ -16,7 +16,7 @@ import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import Projection from '../proj/Projection.js';
|
||||
import Units from '../proj/Units.js';
|
||||
import RenderFeature from '../render/Feature.js';
|
||||
@@ -309,7 +309,7 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
|
||||
let prevEndIndex = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
if (!_ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates, offset, end, 2)) {
|
||||
if (!linearRingIsClockwise(flatCoordinates, offset, end, 2)) {
|
||||
endss.push(ends.slice(prevEndIndex, i));
|
||||
prevEndIndex = i;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js';
|
||||
import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js';
|
||||
import {getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js';
|
||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
||||
import {linearRingsAreOriented, orientLinearRingsArray} from '../geom/flat/orient.js';
|
||||
import {quantizeMultiArray} from '../geom/flat/simplify.js';
|
||||
|
||||
/**
|
||||
@@ -183,7 +183,7 @@ MultiPolygon.prototype.getCoordinates = function(opt_right) {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
_ol_geom_flat_orient_.orientLinearRingss(
|
||||
orientLinearRingsArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
@@ -238,13 +238,13 @@ MultiPolygon.prototype.getInteriorPoints = function() {
|
||||
MultiPolygon.prototype.getOrientedFlatCoordinates = function() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (_ol_geom_flat_orient_.linearRingssAreOriented(
|
||||
if (linearRingsAreOriented(
|
||||
flatCoordinates, 0, this.endss_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
_ol_geom_flat_orient_.orientLinearRingss(
|
||||
orientLinearRingsArray(
|
||||
this.orientedFlatCoordinates_, 0, this.endss_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
|
||||
@@ -17,7 +17,7 @@ import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
||||
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
||||
import {getInteriorPointOfArray} from '../geom/flat/interiorpoint.js';
|
||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
||||
import {linearRingIsOriented, orientLinearRings} from '../geom/flat/orient.js';
|
||||
import {quantizeArray} from '../geom/flat/simplify.js';
|
||||
import {modulo} from '../math.js';
|
||||
|
||||
@@ -173,7 +173,7 @@ Polygon.prototype.getCoordinates = function(opt_right) {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
_ol_geom_flat_orient_.orientLinearRings(
|
||||
orientLinearRings(
|
||||
flatCoordinates, 0, this.ends_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
@@ -279,13 +279,13 @@ Polygon.prototype.getLinearRings = function() {
|
||||
Polygon.prototype.getOrientedFlatCoordinates = function() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (_ol_geom_flat_orient_.linearRingsAreOriented(
|
||||
if (linearRingIsOriented(
|
||||
flatCoordinates, 0, this.ends_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
_ol_geom_flat_orient_.orientLinearRings(
|
||||
orientLinearRings(
|
||||
this.orientedFlatCoordinates_, 0, this.ends_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/geom/flat/orient
|
||||
*/
|
||||
import {coordinates as reverseCoordinates} from '../flat/reverse.js';
|
||||
const _ol_geom_flat_orient_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,7 +11,7 @@ const _ol_geom_flat_orient_ = {};
|
||||
* @param {number} stride Stride.
|
||||
* @return {boolean} Is clockwise.
|
||||
*/
|
||||
_ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset, end, stride) {
|
||||
export function linearRingIsClockwise(flatCoordinates, offset, end, stride) {
|
||||
// http://tinyurl.com/clockwise-method
|
||||
// https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrlinearring.cpp
|
||||
let edge = 0;
|
||||
@@ -26,7 +25,7 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset,
|
||||
y1 = y2;
|
||||
}
|
||||
return edge > 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,11 +41,11 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset,
|
||||
* (counter-clockwise exterior ring and clockwise interior rings).
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
_ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) {
|
||||
export function linearRingIsOriented(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];
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
if (i === 0) {
|
||||
if ((right && isClockwise) || (!right && !isClockwise)) {
|
||||
@@ -60,7 +59,7 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset,
|
||||
offset = end;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -76,15 +75,15 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset,
|
||||
* (counter-clockwise exterior ring and clockwise interior rings).
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
_ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
export function linearRingsAreOriented(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
if (!_ol_geom_flat_orient_.linearRingsAreOriented(
|
||||
if (!linearRingIsOriented(
|
||||
flatCoordinates, offset, endss[i], stride, opt_right)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -100,11 +99,11 @@ _ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset
|
||||
* @param {boolean=} opt_right Follow the right-hand rule for orientation.
|
||||
* @return {number} End.
|
||||
*/
|
||||
_ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends, stride, opt_right) {
|
||||
export function orientLinearRings(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];
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
const reverse = i === 0 ?
|
||||
(right && isClockwise) || (!right && !isClockwise) :
|
||||
@@ -115,7 +114,7 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends
|
||||
offset = end;
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -131,11 +130,10 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends
|
||||
* @param {boolean=} opt_right Follow the right-hand rule for orientation.
|
||||
* @return {number} End.
|
||||
*/
|
||||
_ol_geom_flat_orient_.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
export function orientLinearRingsArray(flatCoordinates, offset, endss, stride, opt_right) {
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
offset = _ol_geom_flat_orient_.orientLinearRings(
|
||||
offset = orientLinearRings(
|
||||
flatCoordinates, offset, endss[i], stride, opt_right);
|
||||
}
|
||||
return offset;
|
||||
};
|
||||
export default _ol_geom_flat_orient_;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {getUid, inherits} from '../../index.js';
|
||||
import {equals} from '../../array.js';
|
||||
import {asArray} from '../../color.js';
|
||||
import {intersects} from '../../extent.js';
|
||||
import _ol_geom_flat_orient_ from '../../geom/flat/orient.js';
|
||||
import {linearRingIsClockwise} from '../../geom/flat/orient.js';
|
||||
import _ol_geom_flat_transform_ from '../../geom/flat/transform.js';
|
||||
import {lineStringIsClosed} from '../../geom/flat/topology.js';
|
||||
import {isEmpty} from '../../obj.js';
|
||||
@@ -252,7 +252,7 @@ WebGLLineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, off
|
||||
|
||||
if (closed) {
|
||||
n = n || numVertices / 7;
|
||||
sign = _ol_geom_flat_orient_.linearRingIsClockwise([p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]], 0, 6, 2)
|
||||
sign = linearRingIsClockwise([p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]], 0, 6, 2)
|
||||
? 1 : -1;
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {asArray} from '../../color.js';
|
||||
import {intersects} from '../../extent.js';
|
||||
import {isEmpty} from '../../obj.js';
|
||||
import {linearRingContainsXY} from '../../geom/flat/contains.js';
|
||||
import _ol_geom_flat_orient_ from '../../geom/flat/orient.js';
|
||||
import {linearRingIsClockwise} from '../../geom/flat/orient.js';
|
||||
import _ol_geom_flat_transform_ from '../../geom/flat/transform.js';
|
||||
import {fragment, vertex} from '../webgl/polygonreplay/defaultshader.js';
|
||||
import Locations from '../webgl/polygonreplay/defaultshader/Locations.js';
|
||||
@@ -140,7 +140,7 @@ WebGLPolygonReplay.prototype.drawCoordinates_ = function(
|
||||
*/
|
||||
WebGLPolygonReplay.prototype.processFlatCoordinates_ = function(
|
||||
flatCoordinates, stride, list, rtree, clockwise) {
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates,
|
||||
const isClockwise = linearRingIsClockwise(flatCoordinates,
|
||||
0, flatCoordinates.length, stride);
|
||||
let i, ii;
|
||||
let n = this.vertices.length / 2;
|
||||
@@ -404,7 +404,7 @@ WebGLPolygonReplay.prototype.clipEars_ = function(list, rtree, simple, ccw) {
|
||||
variableCriterion) {
|
||||
//The diagonal is completely inside the polygon
|
||||
if (simple || p0.reflex === false || p2.reflex === false ||
|
||||
_ol_geom_flat_orient_.linearRingIsClockwise([s0.p0.x, s0.p0.y, p0.x,
|
||||
linearRingIsClockwise([s0.p0.x, s0.p0.y, p0.x,
|
||||
p0.y, p1.x, p1.y, p2.x, p2.y, s3.p1.x, s3.p1.y], 0, 10, 2) === !ccw) {
|
||||
//The diagonal is persumably valid, we have an ear
|
||||
this.indices[numIndices++] = p0.i;
|
||||
@@ -533,7 +533,7 @@ WebGLPolygonReplay.prototype.isClockwise_ = function(list) {
|
||||
flatCoordinates[i++] = seg.p0.y;
|
||||
seg = list.nextItem();
|
||||
} while (seg !== start);
|
||||
return _ol_geom_flat_orient_.linearRingIsClockwise(flatCoordinates, 0, length, 2);
|
||||
return linearRingIsClockwise(flatCoordinates, 0, length, 2);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ol_geom_flat_orient_ from '../../../../../src/ol/geom/flat/orient.js';
|
||||
import {linearRingIsClockwise, linearRingIsOriented,
|
||||
linearRingsAreOriented, orientLinearRings, orientLinearRingsArray} from '../../../../../src/ol/geom/flat/orient.js';
|
||||
|
||||
|
||||
describe('ol.geom.flat.orient', function() {
|
||||
@@ -7,14 +8,14 @@ describe('ol.geom.flat.orient', function() {
|
||||
|
||||
it('identifies clockwise rings', function() {
|
||||
const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0];
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates, 0, flatCoordinates.length, 2);
|
||||
expect(isClockwise).to.be(true);
|
||||
});
|
||||
|
||||
it('identifies anti-clockwise rings', function() {
|
||||
const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3];
|
||||
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates, 0, flatCoordinates.length, 2);
|
||||
expect(isClockwise).to.be(false);
|
||||
});
|
||||
@@ -22,7 +23,7 @@ describe('ol.geom.flat.orient', function() {
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.linearRingsAreOriented()', function() {
|
||||
const oriented = _ol_geom_flat_orient_.linearRingsAreOriented;
|
||||
const oriented = linearRingIsOriented;
|
||||
|
||||
const rightCoords = [
|
||||
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
|
||||
@@ -49,7 +50,7 @@ describe('ol.geom.flat.orient', function() {
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.linearRingssAreOriented()', function() {
|
||||
const oriented = _ol_geom_flat_orient_.linearRingssAreOriented;
|
||||
const oriented = linearRingsAreOriented;
|
||||
|
||||
const rightCoords = [
|
||||
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
|
||||
@@ -80,7 +81,7 @@ describe('ol.geom.flat.orient', function() {
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.orientLinearRings()', function() {
|
||||
const orient = _ol_geom_flat_orient_.orientLinearRings;
|
||||
const orient = orientLinearRings;
|
||||
|
||||
const rightCoords = [
|
||||
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
|
||||
@@ -117,7 +118,7 @@ describe('ol.geom.flat.orient', function() {
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.orientLinearRingss()', function() {
|
||||
const orient = _ol_geom_flat_orient_.orientLinearRingss;
|
||||
const orient = orientLinearRingsArray;
|
||||
|
||||
const rightCoords = [
|
||||
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
|
||||
|
||||
Reference in New Issue
Block a user