Move squaredDistance and squaredSegmentDistance into ol.math
This commit is contained in:
@@ -3,6 +3,7 @@ goog.provide('ol.geom.flat.closest');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.math');
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,7 @@ ol.geom.flat.closest.getMaxSquaredDelta =
|
||||
for (offset += stride; offset < end; offset += stride) {
|
||||
var x2 = flatCoordinates[offset];
|
||||
var y2 = flatCoordinates[offset + 1];
|
||||
var squaredDelta = ol.geom.flat.squaredDistance(x1, y1, x2, y2);
|
||||
var squaredDelta = ol.math.squaredDistance(x1, y1, x2, y2);
|
||||
if (squaredDelta > maxSquaredDelta) {
|
||||
maxSquaredDelta = squaredDelta;
|
||||
}
|
||||
@@ -141,7 +142,7 @@ ol.geom.flat.closest.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
var i, squaredDistance;
|
||||
if (maxDelta === 0) {
|
||||
// All points are identical, so just test the first point.
|
||||
squaredDistance = ol.geom.flat.squaredDistance(
|
||||
squaredDistance = ol.math.squaredDistance(
|
||||
x, y, flatCoordinates[offset], flatCoordinates[offset + 1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
for (i = 0; i < stride; ++i) {
|
||||
@@ -159,8 +160,7 @@ ol.geom.flat.closest.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
while (index < end) {
|
||||
ol.geom.flat.closest.point(
|
||||
flatCoordinates, index - stride, index, stride, x, y, tmpPoint);
|
||||
squaredDistance = ol.geom.flat.squaredDistance(
|
||||
x, y, tmpPoint[0], tmpPoint[1]);
|
||||
squaredDistance = ol.math.squaredDistance(x, y, tmpPoint[0], tmpPoint[1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
for (i = 0; i < stride; ++i) {
|
||||
@@ -188,8 +188,7 @@ ol.geom.flat.closest.getClosestPoint = function(flatCoordinates, offset, end,
|
||||
// Check the closing segment.
|
||||
ol.geom.flat.closest.point(
|
||||
flatCoordinates, end - stride, offset, stride, x, y, tmpPoint);
|
||||
squaredDistance = ol.geom.flat.squaredDistance(
|
||||
x, y, tmpPoint[0], tmpPoint[1]);
|
||||
squaredDistance = ol.math.squaredDistance(x, y, tmpPoint[0], tmpPoint[1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
for (i = 0; i < stride; ++i) {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
goog.provide('ol.geom.flat.simplify');
|
||||
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.math');
|
||||
|
||||
|
||||
/**
|
||||
@@ -101,7 +102,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.geom.flat.squaredSegmentDistance(
|
||||
var squaredDistance = ol.math.squaredSegmentDistance(
|
||||
x, y, x1, y1, x2, y2);
|
||||
if (squaredDistance > maxSquaredDistance) {
|
||||
index = i;
|
||||
@@ -219,7 +220,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.geom.flat.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;
|
||||
|
||||
Reference in New Issue
Block a user