From 82341c779a01aec2769213b8a06cb86c092c12f4 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 30 Jan 2014 16:02:38 +0100 Subject: [PATCH 1/2] Factor out ol.geom.Circle#getRadiusSquared_ --- src/ol/geom/circle.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ol/geom/circle.js b/src/ol/geom/circle.js index aeb9f69827..1ff63e2f72 100644 --- a/src/ol/geom/circle.js +++ b/src/ol/geom/circle.js @@ -106,9 +106,18 @@ ol.geom.Circle.prototype.getExtent = function(opt_extent) { * @return {number} Radius. */ ol.geom.Circle.prototype.getRadius = function() { + return Math.sqrt(this.getRadiusSquared_()); +}; + + +/** + * @private + * @return {number} Radius squared. + */ +ol.geom.Circle.prototype.getRadiusSquared_ = function() { var dx = this.flatCoordinates[this.stride] - this.flatCoordinates[0]; var dy = this.flatCoordinates[this.stride + 1] - this.flatCoordinates[1]; - return Math.sqrt(dx * dx + dy * dy); + return dx * dx + dy * dy; }; From aff32ab67624243a66da7fdf9f4efb50f082f8c8 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 30 Jan 2014 16:03:07 +0100 Subject: [PATCH 2/2] Use getRadiusSquared_ in ol.geom.Circle#containsXY --- src/ol/geom/circle.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ol/geom/circle.js b/src/ol/geom/circle.js index 1ff63e2f72..d6d5c5f510 100644 --- a/src/ol/geom/circle.js +++ b/src/ol/geom/circle.js @@ -71,8 +71,7 @@ ol.geom.Circle.prototype.containsXY = function(x, y) { var flatCoordinates = this.flatCoordinates; var dx = x - flatCoordinates[0]; var dy = y - flatCoordinates[1]; - var r = flatCoordinates[this.stride] - flatCoordinates[0]; - return Math.sqrt(dx * dx + dy * dy) <= r; + return dx * dx + dy * dy <= this.getRadiusSquared_(); };