ol/geom/flat/simplify export
This commit is contained in:
@@ -14,7 +14,7 @@ import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
|||||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||||
import {lineStringLength} from '../geom/flat/length.js';
|
import {lineStringLength} from '../geom/flat/length.js';
|
||||||
import {forEach as forEachSegment} from '../geom/flat/segments.js';
|
import {forEach as forEachSegment} from '../geom/flat/segments.js';
|
||||||
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
|
import {douglasPeucker} from '../geom/flat/simplify.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -205,7 +205,7 @@ LineString.prototype.getFlatMidpoint = function() {
|
|||||||
*/
|
*/
|
||||||
LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker(
|
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||||
const simplifiedLineString = new LineString(null);
|
const simplifiedLineString = new LineString(null);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {linearRing as linearRingArea} from '../geom/flat/area.js';
|
|||||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
||||||
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
||||||
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
||||||
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
|
import {douglasPeucker} from '../geom/flat/simplify.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -104,7 +104,7 @@ LinearRing.prototype.getCoordinates = function() {
|
|||||||
*/
|
*/
|
||||||
LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker(
|
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||||
const simplifiedLinearRing = new LinearRing(null);
|
const simplifiedLinearRing = new LinearRing(null);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
|||||||
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
||||||
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
||||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||||
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
|
import {douglasPeuckerArray} from '../geom/flat/simplify.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -223,7 +223,7 @@ MultiLineString.prototype.getFlatMidpoints = function() {
|
|||||||
MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
const simplifiedEnds = [];
|
const simplifiedEnds = [];
|
||||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeuckers(
|
simplifiedFlatCoordinates.length = douglasPeuckerArray(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
|
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
|
||||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||||
const simplifiedMultiLineString = new MultiLineString(null);
|
const simplifiedMultiLineString = new MultiLineString(null);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js';
|
|||||||
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
|
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
|
||||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||||
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
||||||
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
|
import {quantizeMultiArray} from '../geom/flat/simplify.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -259,7 +259,7 @@ MultiPolygon.prototype.getOrientedFlatCoordinates = function() {
|
|||||||
MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
const simplifiedEndss = [];
|
const simplifiedEndss = [];
|
||||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.quantizess(
|
simplifiedFlatCoordinates.length = quantizeMultiArray(
|
||||||
this.flatCoordinates, 0, this.endss_, this.stride,
|
this.flatCoordinates, 0, this.endss_, this.stride,
|
||||||
Math.sqrt(squaredTolerance),
|
Math.sqrt(squaredTolerance),
|
||||||
simplifiedFlatCoordinates, 0, simplifiedEndss);
|
simplifiedFlatCoordinates, 0, simplifiedEndss);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
|||||||
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
|
import _ol_geom_flat_interiorpoint_ from '../geom/flat/interiorpoint.js';
|
||||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||||
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
import _ol_geom_flat_orient_ from '../geom/flat/orient.js';
|
||||||
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
|
import {quantizeArray} from '../geom/flat/simplify.js';
|
||||||
import {modulo} from '../math.js';
|
import {modulo} from '../math.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -300,7 +300,7 @@ Polygon.prototype.getOrientedFlatCoordinates = function() {
|
|||||||
Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
const simplifiedEnds = [];
|
const simplifiedEnds = [];
|
||||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.quantizes(
|
simplifiedFlatCoordinates.length = quantizeArray(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||||
Math.sqrt(squaredTolerance),
|
Math.sqrt(squaredTolerance),
|
||||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
// POSSIBILITY OF SUCH DAMAGE.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import {squaredSegmentDistance, squaredDistance} from '../../math.js';
|
import {squaredSegmentDistance, squaredDistance} from '../../math.js';
|
||||||
const _ol_geom_flat_simplify_ = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,23 +41,23 @@ const _ol_geom_flat_simplify_ = {};
|
|||||||
* coordinates.
|
* coordinates.
|
||||||
* @return {Array.<number>} Simplified line string.
|
* @return {Array.<number>} Simplified line string.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end,
|
export function simplifyLineString(flatCoordinates, offset, end,
|
||||||
stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
|
stride, squaredTolerance, highQuality, opt_simplifiedFlatCoordinates) {
|
||||||
const simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
|
const simplifiedFlatCoordinates = opt_simplifiedFlatCoordinates !== undefined ?
|
||||||
opt_simplifiedFlatCoordinates : [];
|
opt_simplifiedFlatCoordinates : [];
|
||||||
if (!highQuality) {
|
if (!highQuality) {
|
||||||
end = _ol_geom_flat_simplify_.radialDistance(flatCoordinates, offset, end,
|
end = radialDistance(flatCoordinates, offset, end,
|
||||||
stride, squaredTolerance,
|
stride, squaredTolerance,
|
||||||
simplifiedFlatCoordinates, 0);
|
simplifiedFlatCoordinates, 0);
|
||||||
flatCoordinates = simplifiedFlatCoordinates;
|
flatCoordinates = simplifiedFlatCoordinates;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
stride = 2;
|
stride = 2;
|
||||||
}
|
}
|
||||||
simplifiedFlatCoordinates.length = _ol_geom_flat_simplify_.douglasPeucker(
|
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||||
simplifiedFlatCoordinates, 0);
|
simplifiedFlatCoordinates, 0);
|
||||||
return simplifiedFlatCoordinates;
|
return simplifiedFlatCoordinates;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,7 +71,7 @@ _ol_geom_flat_simplify_.lineString = function(flatCoordinates, offset, end,
|
|||||||
* @param {number} simplifiedOffset Simplified offset.
|
* @param {number} simplifiedOffset Simplified offset.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
export function douglasPeucker(flatCoordinates, offset, end,
|
||||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||||
const n = (end - offset) / stride;
|
const n = (end - offset) / stride;
|
||||||
if (n < 3) {
|
if (n < 3) {
|
||||||
@@ -128,7 +127,7 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,19 +142,19 @@ _ol_geom_flat_simplify_.douglasPeucker = function(flatCoordinates, offset, end,
|
|||||||
* @param {Array.<number>} simplifiedEnds Simplified ends.
|
* @param {Array.<number>} simplifiedEnds Simplified ends.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset,
|
export function douglasPeuckerArray(flatCoordinates, offset,
|
||||||
ends, stride, squaredTolerance, simplifiedFlatCoordinates,
|
ends, stride, squaredTolerance, simplifiedFlatCoordinates,
|
||||||
simplifiedOffset, simplifiedEnds) {
|
simplifiedOffset, simplifiedEnds) {
|
||||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||||
const end = ends[i];
|
const end = ends[i];
|
||||||
simplifiedOffset = _ol_geom_flat_simplify_.douglasPeucker(
|
simplifiedOffset = douglasPeucker(
|
||||||
flatCoordinates, offset, end, stride, squaredTolerance,
|
flatCoordinates, offset, end, stride, squaredTolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset);
|
simplifiedFlatCoordinates, simplifiedOffset);
|
||||||
simplifiedEnds.push(simplifiedOffset);
|
simplifiedEnds.push(simplifiedOffset);
|
||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,20 +169,20 @@ _ol_geom_flat_simplify_.douglasPeuckers = function(flatCoordinates, offset,
|
|||||||
* @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
|
* @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.douglasPeuckerss = function(
|
export function douglasPeuckerMultiArray(
|
||||||
flatCoordinates, offset, endss, stride, squaredTolerance,
|
flatCoordinates, offset, endss, stride, squaredTolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||||
const ends = endss[i];
|
const ends = endss[i];
|
||||||
const simplifiedEnds = [];
|
const simplifiedEnds = [];
|
||||||
simplifiedOffset = _ol_geom_flat_simplify_.douglasPeuckers(
|
simplifiedOffset = douglasPeuckerArray(
|
||||||
flatCoordinates, offset, ends, stride, squaredTolerance,
|
flatCoordinates, offset, ends, stride, squaredTolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||||
simplifiedEndss.push(simplifiedEnds);
|
simplifiedEndss.push(simplifiedEnds);
|
||||||
offset = ends[ends.length - 1];
|
offset = ends[ends.length - 1];
|
||||||
}
|
}
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,7 +196,7 @@ _ol_geom_flat_simplify_.douglasPeuckerss = function(
|
|||||||
* @param {number} simplifiedOffset Simplified offset.
|
* @param {number} simplifiedOffset Simplified offset.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end,
|
export function radialDistance(flatCoordinates, offset, end,
|
||||||
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
stride, squaredTolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||||
if (end <= offset + stride) {
|
if (end <= offset + stride) {
|
||||||
// zero or one point, no simplification possible, so copy and return
|
// zero or one point, no simplification possible, so copy and return
|
||||||
@@ -232,7 +231,7 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end,
|
|||||||
simplifiedFlatCoordinates[simplifiedOffset++] = y2;
|
simplifiedFlatCoordinates[simplifiedOffset++] = y2;
|
||||||
}
|
}
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,9 +239,9 @@ _ol_geom_flat_simplify_.radialDistance = function(flatCoordinates, offset, end,
|
|||||||
* @param {number} tolerance Tolerance.
|
* @param {number} tolerance Tolerance.
|
||||||
* @return {number} Rounded value.
|
* @return {number} Rounded value.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.snap = function(value, tolerance) {
|
export function snap(value, tolerance) {
|
||||||
return tolerance * Math.round(value / tolerance);
|
return tolerance * Math.round(value / tolerance);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,15 +263,15 @@ _ol_geom_flat_simplify_.snap = function(value, tolerance) {
|
|||||||
* @param {number} simplifiedOffset Simplified offset.
|
* @param {number} simplifiedOffset Simplified offset.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride,
|
export function quantize(flatCoordinates, offset, end, stride,
|
||||||
tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
tolerance, simplifiedFlatCoordinates, simplifiedOffset) {
|
||||||
// do nothing if the line is empty
|
// do nothing if the line is empty
|
||||||
if (offset == end) {
|
if (offset == end) {
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
}
|
}
|
||||||
// snap the first coordinate (P1)
|
// snap the first coordinate (P1)
|
||||||
let x1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
let x1 = snap(flatCoordinates[offset], tolerance);
|
||||||
let y1 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
let y1 = snap(flatCoordinates[offset + 1], tolerance);
|
||||||
offset += stride;
|
offset += stride;
|
||||||
// add the first coordinate to the output
|
// add the first coordinate to the output
|
||||||
simplifiedFlatCoordinates[simplifiedOffset++] = x1;
|
simplifiedFlatCoordinates[simplifiedOffset++] = x1;
|
||||||
@@ -281,8 +280,8 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride
|
|||||||
// coordinate (P2)
|
// coordinate (P2)
|
||||||
let x2, y2;
|
let x2, y2;
|
||||||
do {
|
do {
|
||||||
x2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
x2 = snap(flatCoordinates[offset], tolerance);
|
||||||
y2 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
y2 = snap(flatCoordinates[offset + 1], tolerance);
|
||||||
offset += stride;
|
offset += stride;
|
||||||
if (offset == end) {
|
if (offset == end) {
|
||||||
// all coordinates snap to the same value, the line collapses to a point
|
// all coordinates snap to the same value, the line collapses to a point
|
||||||
@@ -296,8 +295,8 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride
|
|||||||
} while (x2 == x1 && y2 == y1);
|
} while (x2 == x1 && y2 == y1);
|
||||||
while (offset < end) {
|
while (offset < end) {
|
||||||
// snap the next coordinate (P3)
|
// snap the next coordinate (P3)
|
||||||
const x3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset], tolerance);
|
const x3 = snap(flatCoordinates[offset], tolerance);
|
||||||
const y3 = _ol_geom_flat_simplify_.snap(flatCoordinates[offset + 1], tolerance);
|
const y3 = snap(flatCoordinates[offset + 1], tolerance);
|
||||||
offset += stride;
|
offset += stride;
|
||||||
// skip P3 if it is equal to P2
|
// skip P3 if it is equal to P2
|
||||||
if (x3 == x2 && y3 == y2) {
|
if (x3 == x2 && y3 == y2) {
|
||||||
@@ -334,7 +333,7 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride
|
|||||||
simplifiedFlatCoordinates[simplifiedOffset++] = x2;
|
simplifiedFlatCoordinates[simplifiedOffset++] = x2;
|
||||||
simplifiedFlatCoordinates[simplifiedOffset++] = y2;
|
simplifiedFlatCoordinates[simplifiedOffset++] = y2;
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,13 +348,13 @@ _ol_geom_flat_simplify_.quantize = function(flatCoordinates, offset, end, stride
|
|||||||
* @param {Array.<number>} simplifiedEnds Simplified ends.
|
* @param {Array.<number>} simplifiedEnds Simplified ends.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.quantizes = function(
|
export function quantizeArray(
|
||||||
flatCoordinates, offset, ends, stride,
|
flatCoordinates, offset, ends, stride,
|
||||||
tolerance,
|
tolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
|
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds) {
|
||||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||||
const end = ends[i];
|
const end = ends[i];
|
||||||
simplifiedOffset = _ol_geom_flat_simplify_.quantize(
|
simplifiedOffset = quantize(
|
||||||
flatCoordinates, offset, end, stride,
|
flatCoordinates, offset, end, stride,
|
||||||
tolerance,
|
tolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset);
|
simplifiedFlatCoordinates, simplifiedOffset);
|
||||||
@@ -363,7 +362,7 @@ _ol_geom_flat_simplify_.quantizes = function(
|
|||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -378,14 +377,14 @@ _ol_geom_flat_simplify_.quantizes = function(
|
|||||||
* @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
|
* @param {Array.<Array.<number>>} simplifiedEndss Simplified endss.
|
||||||
* @return {number} Simplified offset.
|
* @return {number} Simplified offset.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_simplify_.quantizess = function(
|
export function quantizeMultiArray(
|
||||||
flatCoordinates, offset, endss, stride,
|
flatCoordinates, offset, endss, stride,
|
||||||
tolerance,
|
tolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEndss) {
|
||||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||||
const ends = endss[i];
|
const ends = endss[i];
|
||||||
const simplifiedEnds = [];
|
const simplifiedEnds = [];
|
||||||
simplifiedOffset = _ol_geom_flat_simplify_.quantizes(
|
simplifiedOffset = quantizeArray(
|
||||||
flatCoordinates, offset, ends, stride,
|
flatCoordinates, offset, ends, stride,
|
||||||
tolerance,
|
tolerance,
|
||||||
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
simplifiedFlatCoordinates, simplifiedOffset, simplifiedEnds);
|
||||||
@@ -393,5 +392,4 @@ _ol_geom_flat_simplify_.quantizess = function(
|
|||||||
offset = ends[ends.length - 1];
|
offset = ends[ends.length - 1];
|
||||||
}
|
}
|
||||||
return simplifiedOffset;
|
return simplifiedOffset;
|
||||||
};
|
}
|
||||||
export default _ol_geom_flat_simplify_;
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
import {inherits} from '../../index.js';
|
import {inherits} from '../../index.js';
|
||||||
import {asString} from '../../color.js';
|
import {asString} from '../../color.js';
|
||||||
import _ol_geom_flat_simplify_ from '../../geom/flat/simplify.js';
|
import {snap} from '../../geom/flat/simplify.js';
|
||||||
import _ol_render_canvas_ from '../canvas.js';
|
import _ol_render_canvas_ from '../canvas.js';
|
||||||
import CanvasInstruction from '../canvas/Instruction.js';
|
import CanvasInstruction from '../canvas/Instruction.js';
|
||||||
import CanvasReplay from '../canvas/Replay.js';
|
import CanvasReplay from '../canvas/Replay.js';
|
||||||
@@ -199,7 +199,7 @@ CanvasPolygonReplay.prototype.finish = function() {
|
|||||||
if (tolerance !== 0) {
|
if (tolerance !== 0) {
|
||||||
const coordinates = this.coordinates;
|
const coordinates = this.coordinates;
|
||||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||||
coordinates[i] = _ol_geom_flat_simplify_.snap(coordinates[i], tolerance);
|
coordinates[i] = snap(coordinates[i], tolerance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ol_geom_flat_simplify_ from '../../../../../src/ol/geom/flat/simplify.js';
|
import {douglasPeucker, quantize, radialDistance, simplifyLineString} from '../../../../../src/ol/geom/flat/simplify.js';
|
||||||
|
|
||||||
|
|
||||||
describe('ol.geom.flat.simplify', function() {
|
describe('ol.geom.flat.simplify', function() {
|
||||||
@@ -81,31 +81,31 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
866.36, 480.77
|
866.36, 480.77
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('ol.geom.flat.simplify.lineString', function() {
|
describe('ol.geom.flat.simplify.simplifyLineString', function() {
|
||||||
|
|
||||||
it('works with empty line strings', function() {
|
it('works with empty line strings', function() {
|
||||||
expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, true)).to.
|
expect(simplifyLineString([], 0, 0, 2, 1, true)).to.
|
||||||
eql([]);
|
eql([]);
|
||||||
expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, false)).to.
|
expect(simplifyLineString([], 0, 0, 2, 1, false)).to.
|
||||||
eql([]);
|
eql([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with a line string with a single point', function() {
|
it('works with a line string with a single point', function() {
|
||||||
expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, true)).to.
|
expect(simplifyLineString([1, 2], 0, 2, 2, 1, true)).to.
|
||||||
eql([1, 2]);
|
eql([1, 2]);
|
||||||
expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, false)).to.
|
expect(simplifyLineString([1, 2], 0, 2, 2, 1, false)).to.
|
||||||
eql([1, 2]);
|
eql([1, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the expected result with low quality', function() {
|
it('returns the expected result with low quality', function() {
|
||||||
const result = _ol_geom_flat_simplify_.lineString(
|
const result = simplifyLineString(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 25, false);
|
flatCoordinates, 0, flatCoordinates.length, 2, 25, false);
|
||||||
expect(result.length).to.be(simplifiedFlatCoordinates.length);
|
expect(result.length).to.be(simplifiedFlatCoordinates.length);
|
||||||
expect(result).to.eql(simplifiedFlatCoordinates);
|
expect(result).to.eql(simplifiedFlatCoordinates);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the expected result with high quality', function() {
|
it('returns the expected result with high quality', function() {
|
||||||
const result = _ol_geom_flat_simplify_.lineString(
|
const result = simplifyLineString(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 25, true);
|
flatCoordinates, 0, flatCoordinates.length, 2, 25, true);
|
||||||
expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length);
|
expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length);
|
||||||
expect(result).to.eql(simplifiedHighQualityFlatCoordinates);
|
expect(result).to.eql(simplifiedHighQualityFlatCoordinates);
|
||||||
@@ -121,63 +121,63 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with empty line strings', function() {
|
it('works with empty line strings', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[], 0, 0, 2, 1, dest, 0)).to.be(0);
|
[], 0, 0, 2, 1, dest, 0)).to.be(0);
|
||||||
expect(dest).to.eql([]);
|
expect(dest).to.eql([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with a line string with a single point', function() {
|
it('works with a line string with a single point', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
|
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
|
||||||
expect(dest).to.eql([1, 2]);
|
expect(dest).to.eql([1, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with a line string with two points', function() {
|
it('works with a line string with two points', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
|
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([1, 2, 3, 4]);
|
expect(dest).to.eql([1, 2, 3, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the points are widely spaced', function() {
|
it('works when the points are widely spaced', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
|
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
|
||||||
expect(dest).to.eql([0, 0, 1, 0, 2, 0, 3, 0]);
|
expect(dest).to.eql([0, 0, 1, 0, 2, 0, 3, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the spacing matches the tolerance', function() {
|
it('works when the spacing matches the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
|
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
|
||||||
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
|
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the points are closely spaced', function() {
|
it('works when the points are closely spaced', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(6);
|
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(6);
|
||||||
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
|
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the line oscillates with widely spaced points', function() {
|
it('works when the line oscillates with widely spaced points', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).
|
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).
|
||||||
to.be(12);
|
to.be(12);
|
||||||
expect(dest).to.eql([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]);
|
expect(dest).to.eql([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the line oscillates with closely spaced points', function() {
|
it('works when the line oscillates with closely spaced points', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).to.be(4);
|
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 1, 1]);
|
expect(dest).to.eql([0, 0, 1, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the line oscillates within the tolerance', function() {
|
it('works when the line oscillates within the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
|
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
|
||||||
to.be(2);
|
to.be(2);
|
||||||
expect(dest).to.eql([0, 0]);
|
expect(dest).to.eql([0, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with real data', function() {
|
it('works with real data', function() {
|
||||||
expect(_ol_geom_flat_simplify_.radialDistance(
|
expect(radialDistance(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
|
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
|
||||||
to.be(simplifiedRadiallyFlatCoordinates.length);
|
to.be(simplifiedRadiallyFlatCoordinates.length);
|
||||||
expect(dest).to.eql(simplifiedRadiallyFlatCoordinates);
|
expect(dest).to.eql(simplifiedRadiallyFlatCoordinates);
|
||||||
@@ -193,93 +193,93 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with empty line strings', function() {
|
it('works with empty line strings', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[], 0, 0, 2, 1, dest, 0)).to.be(0);
|
[], 0, 0, 2, 1, dest, 0)).to.be(0);
|
||||||
expect(dest).to.eql([]);
|
expect(dest).to.eql([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with a line string with a single point', function() {
|
it('works with a line string with a single point', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
|
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
|
||||||
expect(dest).to.eql([1, 2]);
|
expect(dest).to.eql([1, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with a line string with two points', function() {
|
it('works with a line string with two points', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
|
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([1, 2, 3, 4]);
|
expect(dest).to.eql([1, 2, 3, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the points are widely spaced', function() {
|
it('works when the points are widely spaced', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(4);
|
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 3, 0]);
|
expect(dest).to.eql([0, 0, 3, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the spacing matches the tolerance', function() {
|
it('works when the spacing matches the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(4);
|
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 3, 0]);
|
expect(dest).to.eql([0, 0, 3, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the points are closely spaced', function() {
|
it('works when the points are closely spaced', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(4);
|
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 3, 0]);
|
expect(dest).to.eql([0, 0, 3, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not elimnate points outside the tolerance', function() {
|
it('does not elimnate points outside the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(6);
|
[0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(6);
|
||||||
expect(dest).to.eql([0, 0, 1, 1, 2, 0]);
|
expect(dest).to.eql([0, 0, 1, 1, 2, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does eliminate points within the tolerance', function() {
|
it('does eliminate points within the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4);
|
[0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 2, 0]);
|
expect(dest).to.eql([0, 0, 2, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not eliminate multiple points outside the tolerance', function() {
|
it('does not eliminate multiple points outside the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
|
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
|
||||||
expect(dest).to.eql([0, 0, 1, 1, 1, -1, 2, 0]);
|
expect(dest).to.eql([0, 0, 1, 1, 1, -1, 2, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does eliminate multiple points within the tolerance', function() {
|
it('does eliminate multiple points within the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)).to.be(4);
|
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 2, 0]);
|
expect(dest).to.eql([0, 0, 2, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the line oscillates with widely spaced points', function() {
|
it('works when the line oscillates with widely spaced points', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).to.be(4);
|
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 1, 1]);
|
expect(dest).to.eql([0, 0, 1, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the line oscillates with closely spaced points', function() {
|
it('works when the line oscillates with closely spaced points', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).
|
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).
|
||||||
to.be(4);
|
to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 1, 1]);
|
expect(dest).to.eql([0, 0, 1, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when the line oscillates within the tolerance', function() {
|
it('works when the line oscillates within the tolerance', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
|
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
|
||||||
to.be(4);
|
to.be(4);
|
||||||
expect(dest).to.eql([0, 0, 0, 0]);
|
expect(dest).to.eql([0, 0, 0, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works on small triangles', function() {
|
it('works on small triangles', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
[3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
|
[3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
|
||||||
expect(dest).to.eql([3, 0, 5, 2, 5, 0]);
|
expect(dest).to.eql([3, 0, 5, 2, 5, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is the same as high quality simplification', function() {
|
it('is the same as high quality simplification', function() {
|
||||||
expect(_ol_geom_flat_simplify_.douglasPeucker(
|
expect(douglasPeucker(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
|
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
|
||||||
to.be(simplifiedHighQualityFlatCoordinates.length);
|
to.be(simplifiedHighQualityFlatCoordinates.length);
|
||||||
expect(dest).to.eql(simplifiedHighQualityFlatCoordinates);
|
expect(dest).to.eql(simplifiedHighQualityFlatCoordinates);
|
||||||
@@ -291,28 +291,28 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
|
|
||||||
it('handles empty coordinates', function() {
|
it('handles empty coordinates', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0);
|
[], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0);
|
||||||
expect(simplifiedFlatCoordinates).to.be.empty();
|
expect(simplifiedFlatCoordinates).to.be.empty();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('expands points to a zero-length line', function() {
|
it('expands points to a zero-length line', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
|
[0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('snaps near-by points to the same value', function() {
|
it('snaps near-by points to the same value', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
|
[0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('eliminates duplicate snapped points', function() {
|
it('eliminates duplicate snapped points', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1], 0, 12, 2, 2,
|
[0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1], 0, 12, 2, 2,
|
||||||
simplifiedFlatCoordinates, 0)).to.be(4);
|
simplifiedFlatCoordinates, 0)).to.be(4);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0]);
|
||||||
@@ -320,7 +320,7 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
|
|
||||||
it('eliminates horizontal colinear points', function() {
|
it('eliminates horizontal colinear points', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0, 0, 2, 0, 4, 0, 6, 0], 0, 8, 2, 2,
|
[0, 0, 2, 0, 4, 0, 6, 0], 0, 8, 2, 2,
|
||||||
simplifiedFlatCoordinates, 0)).to.be(4);
|
simplifiedFlatCoordinates, 0)).to.be(4);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, 0]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, 0]);
|
||||||
@@ -328,7 +328,7 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
|
|
||||||
it('eliminates vertical colinear points', function() {
|
it('eliminates vertical colinear points', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0, 0, 0, -2, 0, -4, 0, -6], 0, 8, 2, 2,
|
[0, 0, 0, -2, 0, -4, 0, -6], 0, 8, 2, 2,
|
||||||
simplifiedFlatCoordinates, 0)).to.be(4);
|
simplifiedFlatCoordinates, 0)).to.be(4);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, -6]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, -6]);
|
||||||
@@ -336,7 +336,7 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
|
|
||||||
it('eliminates diagonal colinear points', function() {
|
it('eliminates diagonal colinear points', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0, 0, 2, -2, 4, -4, 6, -6], 0, 8, 2, 2,
|
[0, 0, 2, -2, 4, -4, 6, -6], 0, 8, 2, 2,
|
||||||
simplifiedFlatCoordinates, 0)).to.be(4);
|
simplifiedFlatCoordinates, 0)).to.be(4);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, -6]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, -6]);
|
||||||
@@ -344,7 +344,7 @@ describe('ol.geom.flat.simplify', function() {
|
|||||||
|
|
||||||
it('handles switchbacks', function() {
|
it('handles switchbacks', function() {
|
||||||
const simplifiedFlatCoordinates = [];
|
const simplifiedFlatCoordinates = [];
|
||||||
expect(_ol_geom_flat_simplify_.quantize(
|
expect(quantize(
|
||||||
[0, 0, 2, 0, 0, 0, 4, 0], 0, 8, 2, 2,
|
[0, 0, 2, 0, 0, 0, 4, 0], 0, 8, 2, 2,
|
||||||
simplifiedFlatCoordinates, 0)).to.be(8);
|
simplifiedFlatCoordinates, 0)).to.be(8);
|
||||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0, 0, 0, 4, 0]);
|
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0, 0, 0, 4, 0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user