Check closest point against extent

This commit is contained in:
Tom Payne
2013-12-09 11:31:40 +00:00
parent 66f1826358
commit f4fe0046b2
7 changed files with 30 additions and 1 deletions

View File

@@ -119,7 +119,6 @@ ol.geom.Geometry.prototype.closestPointXY = goog.abstractMethod;
* @return {ol.Coordinate} Closest point. * @return {ol.Coordinate} Closest point.
*/ */
ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) { ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
// FIXME check extent
var closestPoint = goog.isDef(opt_closestPoint) ? var closestPoint = goog.isDef(opt_closestPoint) ?
opt_closestPoint : [NaN, NaN]; opt_closestPoint : [NaN, NaN];
this.closestPointXY(point[0], point[1], closestPoint, Infinity); this.closestPointXY(point[0], point[1], closestPoint, Infinity);

View File

@@ -1,5 +1,6 @@
goog.provide('ol.geom.LinearRing'); goog.provide('ol.geom.LinearRing');
goog.require('ol.extent');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.closest'); goog.require('ol.geom.closest');
goog.require('ol.geom.flat'); goog.require('ol.geom.flat');
@@ -40,6 +41,10 @@ goog.inherits(ol.geom.LinearRing, ol.geom.Geometry);
*/ */
ol.geom.LinearRing.prototype.closestPointXY = ol.geom.LinearRing.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) { function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));

View File

@@ -1,5 +1,6 @@
goog.provide('ol.geom.LineString'); goog.provide('ol.geom.LineString');
goog.require('ol.extent');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.closest'); goog.require('ol.geom.closest');
goog.require('ol.geom.flat'); goog.require('ol.geom.flat');
@@ -40,6 +41,10 @@ goog.inherits(ol.geom.LineString, ol.geom.Geometry);
*/ */
ol.geom.LineString.prototype.closestPointXY = ol.geom.LineString.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) { function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));

View File

@@ -1,5 +1,6 @@
goog.provide('ol.geom.MultiLineString'); goog.provide('ol.geom.MultiLineString');
goog.require('ol.extent');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.LineString'); goog.require('ol.geom.LineString');
goog.require('ol.geom.closest'); goog.require('ol.geom.closest');
@@ -47,6 +48,10 @@ goog.inherits(ol.geom.MultiLineString, ol.geom.Geometry);
*/ */
ol.geom.MultiLineString.prototype.closestPointXY = ol.geom.MultiLineString.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) { function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
this.flatCoordinates, 0, this.ends_, this.stride, 0)); this.flatCoordinates, 0, this.ends_, this.stride, 0));

View File

@@ -1,5 +1,6 @@
goog.provide('ol.geom.MultiPoint'); goog.provide('ol.geom.MultiPoint');
goog.require('ol.extent');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.Point'); goog.require('ol.geom.Point');
goog.require('ol.geom.flat'); goog.require('ol.geom.flat');
@@ -24,6 +25,10 @@ goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
*/ */
ol.geom.MultiPoint.prototype.closestPointXY = ol.geom.MultiPoint.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) { function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
var flatCoordinates = this.flatCoordinates; var flatCoordinates = this.flatCoordinates;
var stride = this.stride; var stride = this.stride;
var i, ii; var i, ii;

View File

@@ -1,5 +1,6 @@
goog.provide('ol.geom.MultiPolygon'); goog.provide('ol.geom.MultiPolygon');
goog.require('ol.extent');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.Polygon'); goog.require('ol.geom.Polygon');
goog.require('ol.geom.closest'); goog.require('ol.geom.closest');
@@ -59,6 +60,10 @@ goog.inherits(ol.geom.MultiPolygon, ol.geom.Geometry);
*/ */
ol.geom.MultiPolygon.prototype.closestPointXY = ol.geom.MultiPolygon.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) { function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta(
this.flatCoordinates, 0, this.endss_, this.stride, 0)); this.flatCoordinates, 0, this.endss_, this.stride, 0));

View File

@@ -1,5 +1,6 @@
goog.provide('ol.geom.Polygon'); goog.provide('ol.geom.Polygon');
goog.require('ol.extent');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
goog.require('ol.geom.LinearRing'); goog.require('ol.geom.LinearRing');
goog.require('ol.geom.closest'); goog.require('ol.geom.closest');
@@ -59,6 +60,10 @@ goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
*/ */
ol.geom.Polygon.prototype.closestPointXY = ol.geom.Polygon.prototype.closestPointXY =
function(x, y, closestPoint, minSquaredDistance) { function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.revision) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
this.flatCoordinates, 0, this.ends_, this.stride, 0)); this.flatCoordinates, 0, this.ends_, this.stride, 0));