Rework isClosed with added tests

This commit is contained in:
GaborFarkas
2016-06-22 16:19:47 +02:00
parent e64549c50c
commit 3f828248b9
3 changed files with 56 additions and 19 deletions

View File

@@ -0,0 +1,20 @@
goog.provide('ol.geom.flat.topology');
goog.require('ol.geom.flat.area');
/**
* Check if the linestring is a boundary.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset.
* @param {number} end End.
* @param {number} stride Stride.
* @return {boolean} The linestring is a boundary.
*/
ol.geom.flat.topology.lineStringIsClosed = function(flatCoordinates, offset, end, stride) {
var lastCoord = end - stride;
if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
return !!ol.geom.flat.area.linearRing(flatCoordinates, offset, end, stride);
}
return false;
};