Merge pull request #1560 from twpayne/hide-oriented-rings
Hide oriented rings
This commit is contained in:
@@ -546,6 +546,51 @@ ol.geom.flat.linearRingsGetInteriorPoint =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<number>} ends Ends.
|
||||
* @param {number} stride Stride.
|
||||
* @return {boolean} `true` if all rings are correctly oriented, `false`
|
||||
* otherwise.
|
||||
*/
|
||||
ol.geom.flat.linearRingsAreOriented =
|
||||
function(flatCoordinates, offset, ends, stride) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
var isClockwise = ol.geom.flat.linearRingIsClockwise(
|
||||
flatCoordinates, offset, end, stride);
|
||||
if (i === 0 ? !isClockwise : isClockwise) {
|
||||
return false;
|
||||
}
|
||||
offset = end;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<Array.<number>>} endss Endss.
|
||||
* @param {number} stride Stride.
|
||||
* @return {boolean} `true` if all rings are correctly oriented, `false`
|
||||
* otherwise.
|
||||
*/
|
||||
ol.geom.flat.linearRingssAreOriented =
|
||||
function(flatCoordinates, offset, endss, stride) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
if (!ol.geom.flat.linearRingsAreOriented(
|
||||
flatCoordinates, offset, endss[i], stride)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
|
||||
@@ -50,6 +50,18 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) {
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.orientedRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
@@ -82,7 +94,7 @@ ol.geom.MultiPolygon.prototype.closestPointXY =
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return ol.geom.closest.getssClosestPoint(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride,
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
};
|
||||
|
||||
@@ -92,7 +104,7 @@ ol.geom.MultiPolygon.prototype.closestPointXY =
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.containsXY = function(x, y) {
|
||||
return ol.geom.flat.linearRingssContainsXY(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, x, y);
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
|
||||
};
|
||||
|
||||
|
||||
@@ -101,7 +113,7 @@ ol.geom.MultiPolygon.prototype.containsXY = function(x, y) {
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getArea = function() {
|
||||
return ol.geom.flat.linearRingssArea(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -130,13 +142,33 @@ ol.geom.MultiPolygon.prototype.getInteriorPoints = function() {
|
||||
var ys = ol.geom.flat.linearRingssMidYs(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.interiorPoints_ = ol.geom.flat.linearRingssGetInteriorPoints(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, ys);
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, ys);
|
||||
this.interiorPointsRevision_ = this.getRevision();
|
||||
}
|
||||
return this.interiorPoints_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Oriented flat coordinates.
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getOrientedFlatCoordinates = function() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
if (ol.geom.flat.linearRingssAreOriented(
|
||||
flatCoordinates, 0, this.endss_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length = ol.geom.flat.orientLinearRingss(
|
||||
this.orientedFlatCoordinates_, 0, this.endss_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
return this.orientedFlatCoordinates_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -159,12 +191,20 @@ ol.geom.MultiPolygon.prototype.getSimplifiedGeometryInternal =
|
||||
* @return {Array.<ol.geom.Polygon>} Polygons.
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getPolygons = function() {
|
||||
// FIXME we should construct the polygons directly from the flat coordinates
|
||||
var coordinates = this.getCoordinates();
|
||||
var layout = this.layout;
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
var endss = this.endss_;
|
||||
var polygons = [];
|
||||
var offset = 0;
|
||||
var i, ii;
|
||||
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
polygons.push(new ol.geom.Polygon(coordinates[i]));
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
var end = ends[ends.length - 1];
|
||||
var polygon = new ol.geom.Polygon(null);
|
||||
polygon.setFlatCoordinates(
|
||||
layout, flatCoordinates.slice(offset, end), ends.slice());
|
||||
polygons.push(polygon);
|
||||
offset = end;
|
||||
}
|
||||
return polygons;
|
||||
};
|
||||
@@ -196,8 +236,6 @@ ol.geom.MultiPolygon.prototype.setCoordinates =
|
||||
var lastEnds = endss[endss.length - 1];
|
||||
this.flatCoordinates.length = lastEnds.length === 0 ?
|
||||
0 : lastEnds[lastEnds.length - 1];
|
||||
ol.geom.flat.orientLinearRingss(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,6 +50,18 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.orientedRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
@@ -92,7 +104,7 @@ ol.geom.Polygon.prototype.closestPointXY =
|
||||
*/
|
||||
ol.geom.Polygon.prototype.containsXY = function(x, y) {
|
||||
return ol.geom.flat.linearRingsContainsXY(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, x, y);
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
|
||||
};
|
||||
|
||||
|
||||
@@ -101,7 +113,7 @@ ol.geom.Polygon.prototype.containsXY = function(x, y) {
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getArea = function() {
|
||||
return ol.geom.flat.linearRingsArea(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -130,7 +142,7 @@ ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
||||
var extent = this.getExtent();
|
||||
var y = (extent[1] + extent[3]) / 2;
|
||||
this.interiorPoint_ = ol.geom.flat.linearRingsGetInteriorPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, y);
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, y);
|
||||
this.interiorPointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.interiorPoint_;
|
||||
@@ -141,16 +153,43 @@ ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
||||
* @return {Array.<ol.geom.LinearRing>} Linear rings.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getLinearRings = function() {
|
||||
var layout = this.layout;
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
var ends = this.ends_;
|
||||
var linearRings = [];
|
||||
var coordinates = this.getCoordinates();
|
||||
var offset = 0;
|
||||
var i, ii;
|
||||
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
linearRings.push(new ol.geom.LinearRing(coordinates[i]));
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
var linearRing = new ol.geom.LinearRing(null);
|
||||
linearRing.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
|
||||
linearRings.push(linearRing);
|
||||
offset = end;
|
||||
}
|
||||
return linearRings;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Oriented flat coordinates.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getOrientedFlatCoordinates = function() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
if (ol.geom.flat.linearRingsAreOriented(
|
||||
flatCoordinates, 0, this.ends_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length = ol.geom.flat.orientLinearRings(
|
||||
this.orientedFlatCoordinates_, 0, this.ends_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
return this.orientedFlatCoordinates_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -192,8 +231,6 @@ ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
var ends = ol.geom.flat.deflateCoordinatess(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
ol.geom.flat.orientLinearRings(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1096,7 +1096,7 @@ ol.render.canvas.PolygonReplay.prototype.drawPolygonGeometry =
|
||||
state.miterLimit, state.lineDash]);
|
||||
}
|
||||
var ends = polygonGeometry.getEnds();
|
||||
var flatCoordinates = polygonGeometry.getFlatCoordinates();
|
||||
var flatCoordinates = polygonGeometry.getOrientedFlatCoordinates();
|
||||
var stride = polygonGeometry.getStride();
|
||||
this.drawFlatCoordinatess_(flatCoordinates, 0, ends, stride);
|
||||
this.endGeometry(polygonGeometry, data);
|
||||
@@ -1132,7 +1132,7 @@ ol.render.canvas.PolygonReplay.prototype.drawMultiPolygonGeometry =
|
||||
state.miterLimit, state.lineDash]);
|
||||
}
|
||||
var endss = multiPolygonGeometry.getEndss();
|
||||
var flatCoordinates = multiPolygonGeometry.getFlatCoordinates();
|
||||
var flatCoordinates = multiPolygonGeometry.getOrientedFlatCoordinates();
|
||||
var stride = multiPolygonGeometry.getStride();
|
||||
var offset = 0;
|
||||
var i, ii;
|
||||
|
||||
Reference in New Issue
Block a user