Skip to content

Commit

Permalink
fix(View): fix picking radius with polygons
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Jan 5, 2022
1 parent 1ee50c8 commit b7be8e9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Utils/FeaturesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function getClosestPoint(point, points, epsilon, offset, count, size) {
return closestPoint;
}

function pointIsInsidePolygon(point, polygonPoints, offset, count, size) {
function pointIsInsidePolygon(point, polygonPoints, epsilon, offset, count, size) {
// ray-casting algorithm based on
// http://wrf.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

Expand All @@ -78,13 +78,14 @@ function pointIsInsidePolygon(point, polygonPoints, offset, count, size) {
let inside = false;
// in first j is last point of polygon
// for each segment of the polygon (j is i -1)
// debugger;
for (let i = offset, j = offset + count - size; i < offset + count; j = i, i += size) {
const xi = polygonPoints[i];
const yi = polygonPoints[i + 1];
const xj = polygonPoints[j];
const yj = polygonPoints[j + 1];

if (pointIsOverLine(point, [xi, yi, xj, yj], epsilon, 0, 4, 2)) { return true; }

// isIntersect semi-infinite ray horizontally with polygon's edge
const isIntersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
Expand All @@ -99,7 +100,7 @@ function pointIsInsidePolygon(point, polygonPoints, offset, count, size) {
function isFeatureSingleGeometryUnderCoordinate(coordinate, type, coordinates, epsilon, offset, count, size) {
if ((type == FEATURE_TYPES.LINE) && pointIsOverLine(coordinate, coordinates, epsilon, offset, count, size)) {
return true;
} else if ((type == FEATURE_TYPES.POLYGON) && pointIsInsidePolygon(coordinate, coordinates, offset, count, size)) {
} else if ((type == FEATURE_TYPES.POLYGON) && pointIsInsidePolygon(coordinate, coordinates, epsilon, offset, count, size)) {
return true;
} else if (type == FEATURE_TYPES.POINT) {
const closestPoint = getClosestPoint(coordinate, coordinates, epsilon, offset, count, size);
Expand Down

0 comments on commit b7be8e9

Please sign in to comment.