Skip to content

Fix point-in-polygon problems#368

Merged
pklampros merged 4 commits intoSpaceGroupUCL:masterfrom
pklampros:fix_point_in_poly
Jul 22, 2020
Merged

Fix point-in-polygon problems#368
pklampros merged 4 commits intoSpaceGroupUCL:masterfrom
pklampros:fix_point_in_poly

Conversation

@pklampros
Copy link
Collaborator

@pklampros pklampros commented Jul 13, 2020

Fixes issues when testing points in polygons.

From my understanding the algorithm used for point-in-polygon testing is a convoluted Ray-casting algorithm whereas we start from the point of interest and move in a direction to hit the sides of the polygon. If we find even sides the point is outside, odd sides within, hence the "counter % 2 != 0" checks. The algorithm is convoluted because the ShapeMap::testPointInPoly function first checks if the point is on the border and then travels left, right, up or down depending on the side and down if the point is found within the polygon. The complexity is also dut to an underlying grid for each shapemap which helps detect shapes and identify whether the point is sitting roughly within the polygon, on its border, left, right, top or bottom, but is only accurate to each cell (the size of which has been defined arbitrarily).

The two fixes provided are:

  1. Make sure the point is not treated as within if it's touching the polygon border
  2. Make sure that when the point is roughly within the polygon, then the algorithm actually checks the cells below for the shape.

@pklampros pklampros force-pushed the fix_point_in_poly branch from bd3d4dc to aaa763b Compare July 15, 2020 12:44
@pklampros pklampros marked this pull request as ready for review July 15, 2020 13:32
@pklampros pklampros requested a review from blsemo July 15, 2020 13:35
@pklampros pklampros merged commit bd5e770 into SpaceGroupUCL:master Jul 22, 2020
@pklampros pklampros deleted the fix_point_in_poly branch July 22, 2020 13:07
pklampros added a commit that referenced this pull request Sep 2, 2020
@pklampros pklampros added this to the 0.8.0 milestone Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant