Transformed
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/flat/simplify
|
||||
*/
|
||||
// Based on simplify-js https://github.com/mourner/simplify-js
|
||||
// Copyright (c) 2012, Vladimir Agafonkin
|
||||
// All rights reserved.
|
||||
@@ -24,9 +27,8 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
goog.provide('ol.geom.flat.simplify');
|
||||
|
||||
goog.require('ol.math');
|
||||
import _ol_math_ from '../../math.js';
|
||||
var _ol_geom_flat_simplify_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,19 +42,19 @@ goog.require('ol.math');
|
||||
* coordinates.
|
||||
* @return {Array.<number>} Simplified line string.
|
||||
*/
|
||||
ol.geom.flat.simplify.lineString = function(flatCoordinates, offset, end,
|
||||
_ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
|
||||
var simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
|
||||
opt_simplifiedFlatCoordinates : [];
|
||||
if (!highQuality) {
|
||||
end = ol.geom.flat.simplify.radialDistance(flatCoordinates, offset, end,
|
||||
end = _ol_geom_flat_simplify_.radialDistance(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
flatCoordinates = simplifiedFlatCoordinates;
|
||||
offset = 0;
|
||||
stride = 2;
|
||||
}
|
||||
simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker(
|
||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker(
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0);
|
||||
return simplifiedFlatCoordinates;
|
||||
@@ -70,7 +72,7 @@ ol.geom.flat.simplify.lineString = function(flatCoordinates, offset, end,
|
||||
* @param {number} simplifiedOffset Simplified offset.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
_ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
var n = (end - offset) / stride;
|
||||
if (n < 3) {
|
||||
@@ -101,7 +103,7 @@ ol.geom.flat.simplify.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
for (i = first + stride; i < last; i += stride) {
|
||||
var x = flatCoordinates[i];
|
||||
var y = flatCoordinates[i + 1];
|
||||
var squaredDistance = ol.math.squaredSegmentDistance(
|
||||
var squaredDistance = _ol_math_.squaredSegmentDistance(
|
||||
x, y, x1, y1, x2, y2);
|
||||
if (squaredDistance > maxSquaredDistance) {
|
||||
index = i;
|
||||
@@ -142,13 +144,13 @@ ol.geom.flat.simplify.douglasPeucker = function(flatCoordinates, offset, end,
|
||||
* @param {Array.<number>} simplifiedEnds Simplified ends.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.douglasPeuckers = function(flatCoordinates, offset,
|
||||
_ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset,
|
||||
ends, stride, squaredTolerance, simplifiedFlatCoordinates,
|
||||
simplifiedOffset, simplifiedEnds) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
simplifiedOffset = ol.geom.flat.simplify.douglasPeucker(
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.douglasPeucker(
|
||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
simplifiedEnds.push(simplifiedOffset);
|
||||
@@ -170,14 +172,14 @@ ol.geom.flat.simplify.douglasPeuckers = function(flatCoordinates, offset,
|
||||
* @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.douglasPeuckerss = function(
|
||||
_ol_geom_flat_simplify_.douglasPeuckerss = function(
|
||||
flatCoordinates, offset, endss, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
var simplifiedEnds = [];
|
||||
simplifiedOffset = ol.geom.flat.simplify.douglasPeuckers(
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.douglasPeuckers(
|
||||
flatCoordinates, offset, ends, stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
simplifiedEndss.push(simplifiedEnds);
|
||||
@@ -198,7 +200,7 @@ ol.geom.flat.simplify.douglasPeuckerss = function(
|
||||
* @param {number} simplifiedOffset Simplified offset.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.radialDistance = function(flatCoordinates, offset, end,
|
||||
_ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end,
|
||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
if (end <= offset + stride) {
|
||||
// zero or one point, no simplification possible, so copy and return
|
||||
@@ -219,7 +221,7 @@ ol.geom.flat.simplify.radialDistance = function(flatCoordinates, offset, end,
|
||||
for (offset += stride; offset < end; offset += stride) {
|
||||
x2 = flatCoordinates[offset];
|
||||
y2 = flatCoordinates[offset + 1];
|
||||
if (ol.math.squaredDistance(x1, y1, x2, y2) > squaredTolerance) {
|
||||
if (_ol_math_.squaredDistance(x1, y1, x2, y2) > squaredTolerance) {
|
||||
// copy point at offset
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = x2;
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = y2;
|
||||
@@ -241,7 +243,7 @@ ol.geom.flat.simplify.radialDistance = function(flatCoordinates, offset, end,
|
||||
* @param {number} tolerance Tolerance.
|
||||
* @return {number} Rounded value.
|
||||
*/
|
||||
ol.geom.flat.simplify.snap = function(value, tolerance) {
|
||||
_ol_geom_flat_simplify_.snap = function(value, tolerance) {
|
||||
return tolerance * Math.round(value / tolerance);
|
||||
};
|
||||
|
||||
@@ -265,15 +267,15 @@ ol.geom.flat.simplify.snap = function(value, tolerance) {
|
||||
* @param {number} simplifiedOffset Simplified offset.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.quantize = function(flatCoordinates, offset, end, stride,
|
||||
_ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride,
|
||||
tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||
// do nothing if the line is empty
|
||||
if (offset == end) {
|
||||
return simplifiedOffset;
|
||||
}
|
||||
// snap the first coordinate (P1)
|
||||
var x1 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance);
|
||||
var y1 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance);
|
||||
var x1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
var y1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
offset += stride;
|
||||
// add the first coordinate to the output
|
||||
simplifiedFlatCoordinates[simplifiedOffset++] = x1;
|
||||
@@ -282,8 +284,8 @@ ol.geom.flat.simplify.quantize = function(flatCoordinates, offset, end, stride,
|
||||
// coordinate (P2)
|
||||
var x2, y2;
|
||||
do {
|
||||
x2 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance);
|
||||
y2 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance);
|
||||
x2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
y2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
offset += stride;
|
||||
if (offset == end) {
|
||||
// all coordinates snap to the same value, the line collapses to a point
|
||||
@@ -298,8 +300,8 @@ ol.geom.flat.simplify.quantize = function(flatCoordinates, offset, end, stride,
|
||||
while (offset < end) {
|
||||
var x3, y3;
|
||||
// snap the next coordinate (P3)
|
||||
x3 = ol.geom.flat.simplify.snap(flatCoordinates[offset], tolerance);
|
||||
y3 = ol.geom.flat.simplify.snap(flatCoordinates[offset + 1], tolerance);
|
||||
x3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
||||
y3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
||||
offset += stride;
|
||||
// skip P3 if it is equal to P2
|
||||
if (x3 == x2 && y3 == y2) {
|
||||
@@ -351,14 +353,14 @@ ol.geom.flat.simplify.quantize = function(flatCoordinates, offset, end, stride,
|
||||
* @param {Array.<number>} simplifiedEnds Simplified ends.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.quantizes = function(
|
||||
_ol_geom_flat_simplify_.quantizes = function(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
simplifiedOffset = ol.geom.flat.simplify.quantize(
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.quantize(
|
||||
flatCoordinates, offset, end, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset);
|
||||
@@ -381,7 +383,7 @@ ol.geom.flat.simplify.quantizes = function(
|
||||
* @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
|
||||
* @return {number} Simplified offset.
|
||||
*/
|
||||
ol.geom.flat.simplify.quantizess = function(
|
||||
_ol_geom_flat_simplify_.quantizess = function(
|
||||
flatCoordinates, offset, endss, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||
@@ -389,7 +391,7 @@ ol.geom.flat.simplify.quantizess = function(
|
||||
for (i = 0, ii = endss.length; i < ii; ++i) {
|
||||
var ends = endss[i];
|
||||
var simplifiedEnds = [];
|
||||
simplifiedOffset = ol.geom.flat.simplify.quantizes(
|
||||
simplifiedOffset = _ol_geom_flat_simplify_.quantizes(
|
||||
flatCoordinates, offset, ends, stride,
|
||||
tolerance,
|
||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||
@@ -398,3 +400,4 @@ ol.geom.flat.simplify.quantizess = function(
|
||||
}
|
||||
return simplifiedOffset;
|
||||
};
|
||||
export default _ol_geom_flat_simplify_;
|
||||
|
||||
Reference in New Issue
Block a user