geos::algorithm::RayCrossingCounter Class Reference

Counts the number of segments crossed by a horizontal ray extending to the right from a given point, in an incremental fashion. More...

`#include <RayCrossingCounter.h>`

## Public Member Functions

| RayCrossingCounter (const geom::CoordinateXY &p_point)
void | countSegment (const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
| Counts a segment.
void | countArc (const geom::CoordinateXY &p1, const geom::CoordinateXY &p2, const geom::CoordinateXY &p3)
void | processSequence (const geom::CoordinateSequence &seq, bool isLinear)
| Counts all segments or arcs in the sequence.
bool | isOnSegment () const
| Reports whether the point lies exactly on one of the supplied segments.
geom::Location | getLocation () const
| Gets the Location of the point relative to the ring, polygon or multipolygon from which the processed segments were provided.
bool | isPointInPolygon () const
| Tests whether the point lies in or on the ring, polygon or multipolygon from which the processed segments were provided.
std::size_t | getCount () const

## Static Public Member Functions

static geom::Location | locatePointInRing (const geom::CoordinateXY &p, const geom::CoordinateSequence &ring)
| Determines the Location of a point in a ring.
static geom::Location | locatePointInRing (const geom::CoordinateXY &p, const std::vector< const geom::Coordinate * > &ring)
| Semantically equal to the above, just different args encoding.
static geom::Location | locatePointInRing (const geom::CoordinateXY &p, const geom::Curve &ring)
static bool | shouldCountCrossing (const geom::CircularArc &arc, const geom::CoordinateXY &q)
static std::array< geom::CoordinateXY, 2 > | pointsIntersectingHorizontalRay (const geom::CircularArc &arc, const geom::CoordinateXY &origin)

## Detailed Description

Counts the number of segments crossed by a horizontal ray extending to the right from a given point, in an incremental fashion.

This can be used to determine whether a point lies in a polygonal geometry. The class determines the situation where the point lies exactly on a segment. When being used for Point-In-Polygon determination, this case allows short-circuiting the evaluation.

This class handles polygonal geometries with any number of shells and holes. The orientation of the shell and hole rings is unimportant. In order to compute a correct location for a given polygonal geometry, it is essential that all segments are counted which

- touch the ray
- lie in in any ring which may contain the point

The only exception is when the point-on-segment situation is detected, in which case no further processing is required. The implication of the above rule is that segments which can be a priori determined to not touch the ray (i.e. by a test of their bounding box or Y-extent) do not need to be counted. This allows for optimization by indexing.

Author
  Martin Davis

## Member Function Documentation

## countSegment()

void geos::algorithm::RayCrossingCounter::countSegment | ( | const geom::CoordinateXY & | p1,
|  | const geom::CoordinateXY & | p2 )

Counts a segment.

Parameters

  p1 | an endpoint of the segment
  p2 | another endpoint of the segment

## getLocation()

geom::Location geos::algorithm::RayCrossingCounter::getLocation | ( |  | ) | const

Gets the Location of the point relative to the ring, polygon or multipolygon from which the processed segments were provided.

This method only determines the correct location if all relevant segments must have been processed.

Returns
  the Location of the point

## isOnSegment()

bool geos::algorithm::RayCrossingCounter::isOnSegment | ( |  | ) | const

inline

Reports whether the point lies exactly on one of the supplied segments.

This method may be called at any time as segments are processed. If the result of this method is true, no further segments need be supplied, since the result will never change again.

Returns
  true if the point lies exactly on a segment

## isPointInPolygon()

bool geos::algorithm::RayCrossingCounter::isPointInPolygon | ( |  | ) | const

Tests whether the point lies in or on the ring, polygon or multipolygon from which the processed segments were provided.

This method only determines the correct location if all relevant segments must have been processed.

Returns
  true if the point lies in or on the supplied polygon

## locatePointInRing()

geom::Location geos::algorithm::RayCrossingCounter::locatePointInRing | ( | const geom::CoordinateXY & | p,
|  | const geom::CoordinateSequence & | ring )

static

Determines the Location of a point in a ring.

This method is an exemplar of how to use this class.

Parameters

  p | the point to test
  ring | an array of Coordinates forming a ring

Returns
  the location of the point in the ring

Referenced by locatePointInRing().

The documentation for this class was generated from the following file:

- RayCrossingCounter.h