erlab.analysis.mask.polygon

Point-in-polygon algorithm.

The implementation has been adapted from the CGAL C++ library.

Functions

bounded_side(points, point)

Compute if a point is inside, outside, or on the boundary of a polygon.

bounded_side_bool(points, point[, boundary])

Compute whether a point lies inside a polygon using bounded_side.

left_vertex(points)

Return the index of the leftmost point of a polygon.

polygon_orientation(points)

right_vertex(points)

Return the index of the rightmost point of a polygon.

which_side_in_slab(point, low, high, points)

Classes

Comparison(value[, names, module, qualname, ...])

Side(value[, names, module, qualname, type, ...])

class erlab.analysis.mask.polygon.Comparison(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

EQUAL = 0
LARGER = 1
SMALLER = -1
class erlab.analysis.mask.polygon.Side(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

ON_BOUNDARY = 0
ON_BOUNDED_SIDE = 1
ON_UNBOUNDED_SIDE = -1
erlab.analysis.mask.polygon.bounded_side(points, point)[source]

Compute if a point is inside, outside, or on the boundary of a polygon.

The polygon is defined by the sequence of points [first,last). Being inside is defined by the odd-even rule. If the point is on a polygon edge, a special value is returned. A simple polygon divides the plane in an unbounded and a bounded region. According to the definition points in the bounded region are inside the polygon.

Parameters:
  • points (ndarray[Any, dtype[float64]]) – (N, 2) input array of polygon vertices.

  • point (tuple[float, float]) – 2-tuple of float specifying point of interest.

Returns:

Enum indicating the location of the point.

Return type:

Side

Note

We shoot a horizontal ray from the point to the right and count the number of intersections with polygon segments. If the number of intersections is odd, the point is inside. We don’t count intersections with horizontal segments. With non-horizontal segments, the top vertex is considered to be part of the segment, but the bottom vertex is not. (Segments are half-closed).

erlab.analysis.mask.polygon.bounded_side_bool(points, point, boundary=True)[source]

Compute whether a point lies inside a polygon using bounded_side.

Parameters:
  • points (ndarray[Any, dtype[float64]]) – (N, 2) input array of polygon vertices.

  • point (tuple[float, float]) – 2-tuple of float specifying point of interest.

  • boundary (bool) – Whether to consider points on the boundary to be inside the polygon. Default is True.

Returns:

True if the point is on the bounded side of the polygon, False otherwise.

Return type:

bool

erlab.analysis.mask.polygon.left_vertex(points)[source]

Return the index of the leftmost point of a polygon.

In case of a tie, the point with the smallest y-coordinate is taken.

Parameters:

points (ndarray[Any, dtype[float64]]) – Input array of polygon vertices.

Returns:

index

Return type:

int

erlab.analysis.mask.polygon.polygon_orientation(points)[source]
erlab.analysis.mask.polygon.right_vertex(points)[source]

Return the index of the rightmost point of a polygon.

In case of a tie, the point with the largest y-coordinate is taken.

Parameters:

points (ndarray[Any, dtype[float64]]) – Input array of polygon vertices.

Return type:

int

erlab.analysis.mask.polygon.which_side_in_slab(point, low, high, points)[source]