ol/geom/flat/closest export
This commit is contained in:
@@ -7,7 +7,7 @@ import {closestSquaredDistanceXY} from '../extent.js';
|
|||||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
import {assignClosestPoint, maxSquaredDelta} 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_interpolate_ from '../geom/flat/interpolate.js';
|
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
||||||
@@ -97,11 +97,11 @@ LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis
|
|||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
}
|
}
|
||||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||||
this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||||
this.maxDeltaRevision_ = this.getRevision();
|
this.maxDeltaRevision_ = this.getRevision();
|
||||||
}
|
}
|
||||||
return _ol_geom_flat_closest_.getClosestPoint(
|
return assignClosestPoint(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import GeometryLayout from '../geom/GeometryLayout.js';
|
|||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
import {linearRing as linearRingArea} from '../geom/flat/area.js';
|
import {linearRing as linearRingArea} from '../geom/flat/area.js';
|
||||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
import {assignClosestPoint, maxSquaredDelta} 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 {douglasPeucker} from '../geom/flat/simplify.js';
|
import {douglasPeucker} from '../geom/flat/simplify.js';
|
||||||
@@ -67,11 +67,11 @@ LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis
|
|||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
}
|
}
|
||||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||||
this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||||
this.maxDeltaRevision_ = this.getRevision();
|
this.maxDeltaRevision_ = this.getRevision();
|
||||||
}
|
}
|
||||||
return _ol_geom_flat_closest_.getClosestPoint(
|
return assignClosestPoint(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import GeometryLayout from '../geom/GeometryLayout.js';
|
|||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import LineString from '../geom/LineString.js';
|
import LineString from '../geom/LineString.js';
|
||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js';
|
||||||
import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
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';
|
||||||
@@ -92,11 +92,11 @@ MultiLineString.prototype.closestPointXY = function(x, y, closestPoint, minSquar
|
|||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
}
|
}
|
||||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||||
this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getsMaxSquaredDelta(
|
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||||
this.maxDeltaRevision_ = this.getRevision();
|
this.maxDeltaRevision_ = this.getRevision();
|
||||||
}
|
}
|
||||||
return _ol_geom_flat_closest_.getsClosestPoint(
|
return assignClosestArrayPoint(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Polygon from '../geom/Polygon.js';
|
|||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
import {linearRingss as linearRingssArea} from '../geom/flat/area.js';
|
import {linearRingss as linearRingssArea} from '../geom/flat/area.js';
|
||||||
import {linearRingss as linearRingssCenter} from '../geom/flat/center.js';
|
import {linearRingss as linearRingssCenter} from '../geom/flat/center.js';
|
||||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
import {assignClosestMultiArrayPoint, multiArrayMaxSquaredDelta} from '../geom/flat/closest.js';
|
||||||
import {linearRingssContainsXY} from '../geom/flat/contains.js';
|
import {linearRingssContainsXY} from '../geom/flat/contains.js';
|
||||||
import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js';
|
import {deflateMultiCoordinatesArray} from '../geom/flat/deflate.js';
|
||||||
import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js';
|
import {inflateMultiCoordinatesArray} from '../geom/flat/inflate.js';
|
||||||
@@ -137,11 +137,11 @@ MultiPolygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredD
|
|||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
}
|
}
|
||||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||||
this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getssMaxSquaredDelta(
|
this.maxDelta_ = Math.sqrt(multiArrayMaxSquaredDelta(
|
||||||
this.flatCoordinates, 0, this.endss_, this.stride, 0));
|
this.flatCoordinates, 0, this.endss_, this.stride, 0));
|
||||||
this.maxDeltaRevision_ = this.getRevision();
|
this.maxDeltaRevision_ = this.getRevision();
|
||||||
}
|
}
|
||||||
return _ol_geom_flat_closest_.getssClosestPoint(
|
return assignClosestMultiArrayPoint(
|
||||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Point from '../geom/Point.js';
|
|||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
import {offset as sphereOffset} from '../sphere.js';
|
import {offset as sphereOffset} from '../sphere.js';
|
||||||
import {linearRings as linearRingsArea} from '../geom/flat/area.js';
|
import {linearRings as linearRingsArea} from '../geom/flat/area.js';
|
||||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js';
|
||||||
import {linearRingsContainsXY} from '../geom/flat/contains.js';
|
import {linearRingsContainsXY} from '../geom/flat/contains.js';
|
||||||
import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
||||||
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
||||||
@@ -127,11 +127,11 @@ Polygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistan
|
|||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
}
|
}
|
||||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||||
this.maxDelta_ = Math.sqrt(_ol_geom_flat_closest_.getsMaxSquaredDelta(
|
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||||
this.maxDeltaRevision_ = this.getRevision();
|
this.maxDeltaRevision_ = this.getRevision();
|
||||||
}
|
}
|
||||||
return _ol_geom_flat_closest_.getsClosestPoint(
|
return assignClosestArrayPoint(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
* @module ol/geom/flat/closest
|
* @module ol/geom/flat/closest
|
||||||
*/
|
*/
|
||||||
import {lerp, squaredDistance as squaredDx} from '../../math.js';
|
import {lerp, squaredDistance as squaredDx} from '../../math.js';
|
||||||
const _ol_geom_flat_closest_ = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +16,7 @@ const _ol_geom_flat_closest_ = {};
|
|||||||
* @param {number} y Y.
|
* @param {number} y Y.
|
||||||
* @param {Array.<number>} closestPoint Closest point.
|
* @param {Array.<number>} closestPoint Closest point.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) {
|
function assignClosest(flatCoordinates, offset1, offset2, stride, x, y, closestPoint) {
|
||||||
const x1 = flatCoordinates[offset1];
|
const x1 = flatCoordinates[offset1];
|
||||||
const y1 = flatCoordinates[offset1 + 1];
|
const y1 = flatCoordinates[offset1 + 1];
|
||||||
const dx = flatCoordinates[offset2] - x1;
|
const dx = flatCoordinates[offset2] - x1;
|
||||||
@@ -44,7 +43,7 @@ _ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, strid
|
|||||||
closestPoint[i] = flatCoordinates[offset + i];
|
closestPoint[i] = flatCoordinates[offset + i];
|
||||||
}
|
}
|
||||||
closestPoint.length = stride;
|
closestPoint.length = stride;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,24 +53,24 @@ _ol_geom_flat_closest_.point = function(flatCoordinates, offset1, offset2, strid
|
|||||||
* @param {number} offset Offset.
|
* @param {number} offset Offset.
|
||||||
* @param {number} end End.
|
* @param {number} end End.
|
||||||
* @param {number} stride Stride.
|
* @param {number} stride Stride.
|
||||||
* @param {number} maxSquaredDelta Max squared delta.
|
* @param {number} max Max squared delta.
|
||||||
* @return {number} Max squared delta.
|
* @return {number} Max squared delta.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.getMaxSquaredDelta = function(flatCoordinates, offset, end, stride, maxSquaredDelta) {
|
export function maxSquaredDelta(flatCoordinates, offset, end, stride, max) {
|
||||||
let x1 = flatCoordinates[offset];
|
let x1 = flatCoordinates[offset];
|
||||||
let y1 = flatCoordinates[offset + 1];
|
let y1 = flatCoordinates[offset + 1];
|
||||||
for (offset += stride; offset < end; offset += stride) {
|
for (offset += stride; offset < end; offset += stride) {
|
||||||
const x2 = flatCoordinates[offset];
|
const x2 = flatCoordinates[offset];
|
||||||
const y2 = flatCoordinates[offset + 1];
|
const y2 = flatCoordinates[offset + 1];
|
||||||
const squaredDelta = squaredDx(x1, y1, x2, y2);
|
const squaredDelta = squaredDx(x1, y1, x2, y2);
|
||||||
if (squaredDelta > maxSquaredDelta) {
|
if (squaredDelta > max) {
|
||||||
maxSquaredDelta = squaredDelta;
|
max = squaredDelta;
|
||||||
}
|
}
|
||||||
x1 = x2;
|
x1 = x2;
|
||||||
y1 = y2;
|
y1 = y2;
|
||||||
}
|
}
|
||||||
return maxSquaredDelta;
|
return max;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,18 +78,18 @@ _ol_geom_flat_closest_.getMaxSquaredDelta = function(flatCoordinates, offset, en
|
|||||||
* @param {number} offset Offset.
|
* @param {number} offset Offset.
|
||||||
* @param {Array.<number>} ends Ends.
|
* @param {Array.<number>} ends Ends.
|
||||||
* @param {number} stride Stride.
|
* @param {number} stride Stride.
|
||||||
* @param {number} maxSquaredDelta Max squared delta.
|
* @param {number} max Max squared delta.
|
||||||
* @return {number} Max squared delta.
|
* @return {number} Max squared delta.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.getsMaxSquaredDelta = function(flatCoordinates, offset, ends, stride, maxSquaredDelta) {
|
export function arrayMaxSquaredDelta(flatCoordinates, offset, ends, stride, max) {
|
||||||
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];
|
||||||
maxSquaredDelta = _ol_geom_flat_closest_.getMaxSquaredDelta(
|
max = maxSquaredDelta(
|
||||||
flatCoordinates, offset, end, stride, maxSquaredDelta);
|
flatCoordinates, offset, end, stride, max);
|
||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
return maxSquaredDelta;
|
return max;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,18 +97,18 @@ _ol_geom_flat_closest_.getsMaxSquaredDelta = function(flatCoordinates, offset, e
|
|||||||
* @param {number} offset Offset.
|
* @param {number} offset Offset.
|
||||||
* @param {Array.<Array.<number>>} endss Endss.
|
* @param {Array.<Array.<number>>} endss Endss.
|
||||||
* @param {number} stride Stride.
|
* @param {number} stride Stride.
|
||||||
* @param {number} maxSquaredDelta Max squared delta.
|
* @param {number} max Max squared delta.
|
||||||
* @return {number} Max squared delta.
|
* @return {number} Max squared delta.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.getssMaxSquaredDelta = function(flatCoordinates, offset, endss, stride, maxSquaredDelta) {
|
export function multiArrayMaxSquaredDelta(flatCoordinates, offset, endss, stride, max) {
|
||||||
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];
|
||||||
maxSquaredDelta = _ol_geom_flat_closest_.getsMaxSquaredDelta(
|
max = arrayMaxSquaredDelta(
|
||||||
flatCoordinates, offset, ends, stride, maxSquaredDelta);
|
flatCoordinates, offset, ends, stride, max);
|
||||||
offset = ends[ends.length - 1];
|
offset = ends[ends.length - 1];
|
||||||
}
|
}
|
||||||
return maxSquaredDelta;
|
return max;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +125,7 @@ _ol_geom_flat_closest_.getssMaxSquaredDelta = function(flatCoordinates, offset,
|
|||||||
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
||||||
* @return {number} Minimum squared distance.
|
* @return {number} Minimum squared distance.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
export function assignClosestPoint(flatCoordinates, offset, end,
|
||||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||||
opt_tmpPoint) {
|
opt_tmpPoint) {
|
||||||
if (offset == end) {
|
if (offset == end) {
|
||||||
@@ -150,7 +149,7 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
|||||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||||
let index = offset + stride;
|
let index = offset + stride;
|
||||||
while (index < end) {
|
while (index < end) {
|
||||||
_ol_geom_flat_closest_.point(
|
assignClosest(
|
||||||
flatCoordinates, index - stride, index, stride, x, y, tmpPoint);
|
flatCoordinates, index - stride, index, stride, x, y, tmpPoint);
|
||||||
squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]);
|
squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]);
|
||||||
if (squaredDistance < minSquaredDistance) {
|
if (squaredDistance < minSquaredDistance) {
|
||||||
@@ -178,7 +177,7 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
|||||||
}
|
}
|
||||||
if (isRing) {
|
if (isRing) {
|
||||||
// Check the closing segment.
|
// Check the closing segment.
|
||||||
_ol_geom_flat_closest_.point(
|
assignClosest(
|
||||||
flatCoordinates, end - stride, offset, stride, x, y, tmpPoint);
|
flatCoordinates, end - stride, offset, stride, x, y, tmpPoint);
|
||||||
squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]);
|
squaredDistance = squaredDx(x, y, tmpPoint[0], tmpPoint[1]);
|
||||||
if (squaredDistance < minSquaredDistance) {
|
if (squaredDistance < minSquaredDistance) {
|
||||||
@@ -190,7 +189,7 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,19 +206,19 @@ _ol_geom_flat_closest_.getClosestPoint = function(flatCoordinates, offset, end,
|
|||||||
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
||||||
* @return {number} Minimum squared distance.
|
* @return {number} Minimum squared distance.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.getsClosestPoint = function(flatCoordinates, offset, ends,
|
export function assignClosestArrayPoint(flatCoordinates, offset, ends,
|
||||||
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||||
opt_tmpPoint) {
|
opt_tmpPoint) {
|
||||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||||
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];
|
||||||
minSquaredDistance = _ol_geom_flat_closest_.getClosestPoint(
|
minSquaredDistance = assignClosestPoint(
|
||||||
flatCoordinates, offset, end, stride,
|
flatCoordinates, offset, end, stride,
|
||||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,17 +235,16 @@ _ol_geom_flat_closest_.getsClosestPoint = function(flatCoordinates, offset, ends
|
|||||||
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
* @param {Array.<number>=} opt_tmpPoint Temporary point object.
|
||||||
* @return {number} Minimum squared distance.
|
* @return {number} Minimum squared distance.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_closest_.getssClosestPoint = function(flatCoordinates, offset,
|
export function assignClosestMultiArrayPoint(flatCoordinates, offset,
|
||||||
endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
endss, stride, maxDelta, isRing, x, y, closestPoint, minSquaredDistance,
|
||||||
opt_tmpPoint) {
|
opt_tmpPoint) {
|
||||||
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
|
||||||
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];
|
||||||
minSquaredDistance = _ol_geom_flat_closest_.getsClosestPoint(
|
minSquaredDistance = assignClosestArrayPoint(
|
||||||
flatCoordinates, offset, ends, stride,
|
flatCoordinates, offset, ends, stride,
|
||||||
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
maxDelta, isRing, x, y, closestPoint, minSquaredDistance, tmpPoint);
|
||||||
offset = ends[ends.length - 1];
|
offset = ends[ends.length - 1];
|
||||||
}
|
}
|
||||||
return minSquaredDistance;
|
return minSquaredDistance;
|
||||||
};
|
}
|
||||||
export default _ol_geom_flat_closest_;
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ol_geom_flat_closest_ from '../../../../../src/ol/geom/flat/closest.js';
|
import {assignClosestPoint, maxSquaredDelta} from '../../../../../src/ol/geom/flat/closest.js';
|
||||||
|
|
||||||
|
|
||||||
describe('ol.geom.flat.closest', function() {
|
describe('ol.geom.flat.closest', function() {
|
||||||
@@ -10,7 +10,7 @@ describe('ol.geom.flat.closest', function() {
|
|||||||
describe('ol.geom.flat.closest.getMaxSquaredDelta', function() {
|
describe('ol.geom.flat.closest.getMaxSquaredDelta', function() {
|
||||||
|
|
||||||
it('returns the expected value in simple cases', function() {
|
it('returns the expected value in simple cases', function() {
|
||||||
expect(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
expect(maxSquaredDelta(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9);
|
flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -19,23 +19,23 @@ describe('ol.geom.flat.closest', function() {
|
|||||||
describe('ol.geom.flat.closest.getClosestPoint', function() {
|
describe('ol.geom.flat.closest.getClosestPoint', function() {
|
||||||
|
|
||||||
it('returns the expected value', function() {
|
it('returns the expected value', function() {
|
||||||
const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
const maxDelta = Math.sqrt(maxSquaredDelta(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 0));
|
flatCoordinates, 0, flatCoordinates.length, 2, 0));
|
||||||
expect(maxDelta).to.be(3);
|
expect(maxDelta).to.be(3);
|
||||||
const closestPoint = [NaN, NaN];
|
const closestPoint = [NaN, NaN];
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0);
|
maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0);
|
||||||
expect(closestPoint).to.eql([0, 0]);
|
expect(closestPoint).to.eql([0, 0]);
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1);
|
maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1);
|
||||||
expect(closestPoint).to.eql([4, 0]);
|
expect(closestPoint).to.eql([4, 0]);
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4);
|
maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4);
|
||||||
expect(closestPoint).to.eql([5, 0]);
|
expect(closestPoint).to.eql([5, 0]);
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000);
|
maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000);
|
||||||
expect(closestPoint).to.eql([10, 0]);
|
expect(closestPoint).to.eql([10, 0]);
|
||||||
@@ -78,7 +78,7 @@ describe('ol.geom.flat.closest', function() {
|
|||||||
describe('ol.geom.closet.maSquaredDelta', function() {
|
describe('ol.geom.closet.maSquaredDelta', function() {
|
||||||
|
|
||||||
it('returns the expected value', function() {
|
it('returns the expected value', function() {
|
||||||
expect(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
expect(maxSquaredDelta(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 0)).
|
flatCoordinates, 0, flatCoordinates.length, 2, 0)).
|
||||||
to.roughlyEqual(1389.1058, 1e-9);
|
to.roughlyEqual(1389.1058, 1e-9);
|
||||||
});
|
});
|
||||||
@@ -88,21 +88,21 @@ describe('ol.geom.flat.closest', function() {
|
|||||||
describe('ol.geom.flat.closest.getClosestPoint', function() {
|
describe('ol.geom.flat.closest.getClosestPoint', function() {
|
||||||
|
|
||||||
it('returns the expected value', function() {
|
it('returns the expected value', function() {
|
||||||
const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
const maxDelta = Math.sqrt(maxSquaredDelta(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2, 0));
|
flatCoordinates, 0, flatCoordinates.length, 2, 0));
|
||||||
expect(maxDelta).to.roughlyEqual(Math.sqrt(1389.1058), 1e-9);
|
expect(maxDelta).to.roughlyEqual(Math.sqrt(1389.1058), 1e-9);
|
||||||
const closestPoint = [NaN, NaN];
|
const closestPoint = [NaN, NaN];
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 0, 0, closestPoint, Infinity)).
|
maxDelta, false, 0, 0, closestPoint, Infinity)).
|
||||||
to.roughlyEqual(110902.405, 1e-9);
|
to.roughlyEqual(110902.405, 1e-9);
|
||||||
expect(closestPoint).to.eql([292.41, 159.37]);
|
expect(closestPoint).to.eql([292.41, 159.37]);
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 500, 500, closestPoint, Infinity)).
|
maxDelta, false, 500, 500, closestPoint, Infinity)).
|
||||||
to.roughlyEqual(106407.905, 1e-9);
|
to.roughlyEqual(106407.905, 1e-9);
|
||||||
expect(closestPoint).to.eql([671.55, 222.55]);
|
expect(closestPoint).to.eql([671.55, 222.55]);
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, 2,
|
flatCoordinates, 0, flatCoordinates.length, 2,
|
||||||
maxDelta, false, 1000, 500, closestPoint, Infinity)).
|
maxDelta, false, 1000, 500, closestPoint, Infinity)).
|
||||||
to.roughlyEqual(18229.4425, 1e-9);
|
to.roughlyEqual(18229.4425, 1e-9);
|
||||||
@@ -121,11 +121,11 @@ describe('ol.geom.flat.closest', function() {
|
|||||||
describe('ol.geom.flat.closest.getClosestPoint', function() {
|
describe('ol.geom.flat.closest.getClosestPoint', function() {
|
||||||
|
|
||||||
it('interpolates M coordinates', function() {
|
it('interpolates M coordinates', function() {
|
||||||
const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
|
const maxDelta = Math.sqrt(maxSquaredDelta(
|
||||||
flatCoordinates, 0, flatCoordinates.length, stride, 0));
|
flatCoordinates, 0, flatCoordinates.length, stride, 0));
|
||||||
expect(maxDelta).to.roughlyEqual(Math.sqrt(8), 1e-9);
|
expect(maxDelta).to.roughlyEqual(Math.sqrt(8), 1e-9);
|
||||||
const closestPoint = [NaN, NaN];
|
const closestPoint = [NaN, NaN];
|
||||||
expect(_ol_geom_flat_closest_.getClosestPoint(
|
expect(assignClosestPoint(
|
||||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||||
maxDelta, false, 1, 1, closestPoint, Infinity)).
|
maxDelta, false, 1, 1, closestPoint, Infinity)).
|
||||||
to.roughlyEqual(0, 1e-9);
|
to.roughlyEqual(0, 1e-9);
|
||||||
|
|||||||
Reference in New Issue
Block a user