diff options
author | Abhijith Sheheer <abhijithsheheer@gmail.com> | 2019-10-11 17:48:41 +0000 |
---|---|---|
committer | Abhijith Sheheer <abhijithsheheer@gmail.com> | 2019-10-11 17:48:41 +0000 |
commit | 5eaf1af6fb8026f362ce6ae0695b74ba1c8bf0fd (patch) | |
tree | 1dca96f9204b4c41f7bf22327c44ca1df07a1e42 /src/contains.js | |
parent | 036b4ce8c034a72c94b1c5d23ee033909fd71d0f (diff) |
New upstream version 1.11.6
Diffstat (limited to 'src/contains.js')
-rw-r--r-- | src/contains.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/contains.js b/src/contains.js index 952a62d..3b8e0c8 100644 --- a/src/contains.js +++ b/src/contains.js @@ -1,6 +1,6 @@ import {default as polygonContains} from "./polygonContains"; import {default as distance} from "./distance"; -import {epsilon, radians} from "./math"; +import {epsilon2, radians} from "./math"; var containsObjectType = { Feature: function(object, point) { @@ -59,10 +59,23 @@ function containsPoint(coordinates, point) { } function containsLine(coordinates, point) { - var ab = distance(coordinates[0], coordinates[1]), - ao = distance(coordinates[0], point), - ob = distance(point, coordinates[1]); - return ao + ob <= ab + epsilon; + var ao, bo, ab; + for (var i = 0, n = coordinates.length; i < n; i++) { + bo = distance(coordinates[i], point); + if (bo === 0) return true; + if (i > 0) { + ab = distance(coordinates[i], coordinates[i - 1]); + if ( + ab > 0 && + ao <= ab && + bo <= ab && + (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab + ) + return true; + } + ao = bo; + } + return false; } function containsPolygon(coordinates, point) { |