From 7a0336a9efb4f52e8cc0224af9ac653e97c4498e Mon Sep 17 00:00:00 2001 From: Pierre GIRAUD Date: Fri, 13 Jan 2012 17:36:23 +0100 Subject: [PATCH] Fixing a wrong calculation in LinearRing::containsPoint --- lib/OpenLayers/Geometry/LinearRing.js | 2 +- tests/Geometry/LinearRing.html | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Geometry/LinearRing.js b/lib/OpenLayers/Geometry/LinearRing.js index c8b960915c..bcb9ea4c4b 100644 --- a/lib/OpenLayers/Geometry/LinearRing.js +++ b/lib/OpenLayers/Geometry/LinearRing.js @@ -294,7 +294,7 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class( var px = approx(point.x, digs); var py = approx(point.y, digs); function getX(y, x1, y1, x2, y2) { - return (((x1 - x2) * y) + ((x2 * y1) - (x1 * y2))) / (y1 - y2); + return (y-y2)*((x2-x1)/(y2-y1)) + x2; } var numSeg = this.components.length - 1; var start, end, x1, y1, x2, y2, cx, cy; diff --git a/tests/Geometry/LinearRing.html b/tests/Geometry/LinearRing.html index 5cacd89eb7..20ef87efdd 100644 --- a/tests/Geometry/LinearRing.html +++ b/tests/Geometry/LinearRing.html @@ -250,6 +250,22 @@ "resize correctly adjusts y of component 4"); } + function test_LinearRing_containsPoint(t) { + t.plan(1); + + var components = [ + new OpenLayers.Geometry.Point(-10812863.417266,3923827.912779), + new OpenLayers.Geometry.Point(-10812863.417264,3923951.5257855), + new OpenLayers.Geometry.Point(-10812309.24881,3923990.9386282), + new OpenLayers.Geometry.Point(-10812751.15038,3923798.0545649) + ]; + + var ring = new OpenLayers.Geometry.LinearRing(components); + var point = new OpenLayers.Geometry.Point(-10812964.078829, 3923856.9524225); + + t.ok(!ring.containsPoint(point), + "containsPoint correctly returns false for point outside"); + }