GEOS  3.13.0dev
Public Types | Public Member Functions | Static Public Member Functions | List of all members
geos::algorithm::LineIntersector Class Reference

A LineIntersector is an algorithm that can both test whether two line segments intersect and compute the intersection point if they do. More...

#include <LineIntersector.h>

Public Types

enum  intersection_type : uint8_t { NO_INTERSECTION = 0 , POINT_INTERSECTION = 1 , COLLINEAR_INTERSECTION = 2 }
 

Public Member Functions

 LineIntersector (const geom::PrecisionModel *initialPrecisionModel=nullptr)
 
bool isInteriorIntersection ()
 Tests whether either intersection point is an interior point of one of the input segments. More...
 
bool isInteriorIntersection (std::size_t inputLineIndex)
 Tests whether either intersection point is an interior point of the specified input segment. More...
 
void setPrecisionModel (const geom::PrecisionModel *newPM)
 
template<typename C1 , typename C2 >
void computeIntersection (const C1 &p1, const C1 &p2, const C2 &p3, const C2 &p4)
 Computes the intersection of the lines p1-p2 and p3-p4.
 
void computeIntersection (const geom::CoordinateSequence &p, std::size_t p0, const geom::CoordinateSequence &q, std::size_t q0)
 Compute the intersection between two segments, given a sequence and starting index of each.
 
std::string toString () const
 
bool hasIntersection () const
 
const geom::CoordinateXY * getEndpoint (std::size_t segmentIndex, std::size_t ptIndex) const
 
size_t getIntersectionNum () const
 
const geom::CoordinateXYZM & getIntersection (std::size_t intIndex) const
 
bool isIntersection (const geom::Coordinate &pt) const
 Test whether a point is a intersection point of two line segments. More...
 
bool isProper () const
 Tests whether an intersection is proper. More...
 
const geom::CoordinategetIntersectionAlongSegment (std::size_t segmentIndex, std::size_t intIndex)
 Computes the intIndex'th intersection point in the direction of a specified input line segment. More...
 
std::size_t getIndexAlongSegment (std::size_t segmentIndex, std::size_t intIndex)
 Computes the index of the intIndex'th intersection point in the direction of a specified input line segment. More...
 
double getEdgeDistance (std::size_t geomIndex, std::size_t intIndex) const
 Computes the "edge distance" of an intersection point along the specified input line segment. More...
 

Static Public Member Functions

static double computeEdgeDistance (const geom::CoordinateXY &p, const geom::CoordinateXY &p0, const geom::CoordinateXY &p1)
 
static double nonRobustComputeEdgeDistance (const geom::Coordinate &p, const geom::Coordinate &p1, const geom::Coordinate &p2)
 
static bool isSameSignAndNonZero (double a, double b)
 

Detailed Description

A LineIntersector is an algorithm that can both test whether two line segments intersect and compute the intersection point if they do.

The intersection point may be computed in a precise or non-precise manner. Computing it precisely involves rounding it to an integer. (This assumes that the input coordinates have been made precise by scaling them to an integer grid.)

Member Enumeration Documentation

◆ intersection_type

Enumerator
NO_INTERSECTION 

Indicates that line segments do not intersect.

POINT_INTERSECTION 

Indicates that line segments intersect in a single point.

COLLINEAR_INTERSECTION 

Indicates that line segments intersect in a line segment.

Member Function Documentation

◆ computeEdgeDistance()

static double geos::algorithm::LineIntersector::computeEdgeDistance ( const geom::CoordinateXY &  p,
const geom::CoordinateXY &  p0,
const geom::CoordinateXY &  p1 
)
static

Computes the "edge distance" of an intersection point p in an edge.

The edge distance is a metric of the point along the edge. The metric used is a robust and easy to compute metric function. It is not equivalent to the usual Euclidean metric. It relies on the fact that either the x or the y ordinates of the points in the edge are unique, depending on whether the edge is longer in the horizontal or vertical direction.

NOTE: This function may produce incorrect distances for inputs where p is not precisely on p1-p2 (E.g. p = (139,9) p1 = (139,10), p2 = (280,1) produces distanct 0.0, which is incorrect.

My hypothesis is that the function is safe to use for points which are the result of rounding points which lie on the line, but not safe to use for truncated points.

◆ getEdgeDistance()

double geos::algorithm::LineIntersector::getEdgeDistance ( std::size_t  geomIndex,
std::size_t  intIndex 
) const

Computes the "edge distance" of an intersection point along the specified input line segment.

Parameters
geomIndexis 0 or 1
intIndexis 0 or 1
Returns
the edge distance of the intersection point

◆ getEndpoint()

const geom::CoordinateXY* geos::algorithm::LineIntersector::getEndpoint ( std::size_t  segmentIndex,
std::size_t  ptIndex 
) const
inline

Gets an endpoint of an input segment.

Parameters
segmentIndexthe index of the input segment (0 or 1)
ptIndexthe index of the endpoint (0 or 1)
Returns
the specified endpoint

◆ getIndexAlongSegment()

std::size_t geos::algorithm::LineIntersector::getIndexAlongSegment ( std::size_t  segmentIndex,
std::size_t  intIndex 
)

Computes the index of the intIndex'th intersection point in the direction of a specified input line segment.

Parameters
segmentIndexis 0 or 1
intIndexis 0 or 1
Returns
the index of the intersection point along the segment (0 or 1)

◆ getIntersection()

const geom::CoordinateXYZM& geos::algorithm::LineIntersector::getIntersection ( std::size_t  intIndex) const
inline

Returns the intIndex'th intersection point

Parameters
intIndexis 0 or 1
Returns
the intIndex'th intersection point

Referenced by geos::noding::NodedSegmentString::addIntersection().

◆ getIntersectionAlongSegment()

const geom::Coordinate& geos::algorithm::LineIntersector::getIntersectionAlongSegment ( std::size_t  segmentIndex,
std::size_t  intIndex 
)

Computes the intIndex'th intersection point in the direction of a specified input line segment.

Parameters
segmentIndexis 0 or 1
intIndexis 0 or 1
Returns
the intIndex'th intersection point in the direction of the specified input line segment

◆ getIntersectionNum()

size_t geos::algorithm::LineIntersector::getIntersectionNum ( ) const
inline

Returns the number of intersection points found.

This will be either 0, 1 or 2.

Referenced by geos::noding::NodedSegmentString::addIntersections().

◆ hasIntersection()

bool geos::algorithm::LineIntersector::hasIntersection ( ) const
inline

Tests whether the input geometries intersect.

Returns
true if the input geometries intersect

◆ isInteriorIntersection() [1/2]

bool geos::algorithm::LineIntersector::isInteriorIntersection ( )
inline

Tests whether either intersection point is an interior point of one of the input segments.

Returns
true if either intersection point is in the interior of one of the input segments

◆ isInteriorIntersection() [2/2]

bool geos::algorithm::LineIntersector::isInteriorIntersection ( std::size_t  inputLineIndex)
inline

Tests whether either intersection point is an interior point of the specified input segment.

Returns
true if either intersection point is in the interior of the input segment

◆ isIntersection()

bool geos::algorithm::LineIntersector::isIntersection ( const geom::Coordinate pt) const
inline

Test whether a point is a intersection point of two line segments.

Note that if the intersection is a line segment, this method only tests for equality with the endpoints of the intersection segment. It does not return true if the input point is internal to the intersection segment.

Returns
true if the input point is one of the intersection points.

◆ isProper()

bool geos::algorithm::LineIntersector::isProper ( ) const
inline

Tests whether an intersection is proper.

The intersection between two line segments is considered proper if they intersect in a single point in the interior of both segments (e.g. the intersection is a single point and is not equal to any of the endpoints).

The intersection between a point and a line segment is considered proper if the point lies in the interior of the segment (e.g. is not equal to either of the endpoints).

Returns
true if the intersection is proper

◆ isSameSignAndNonZero()

static bool geos::algorithm::LineIntersector::isSameSignAndNonZero ( double  a,
double  b 
)
static

Returns false if both numbers are zero.

Returns
true if both numbers are positive or if both numbers are negative.

◆ setPrecisionModel()

void geos::algorithm::LineIntersector::setPrecisionModel ( const geom::PrecisionModel newPM)
inline

Force computed intersection to be rounded to a given precision model.

No getter is provided, because the precision model is not required to be specified.

Parameters
newPMthe PrecisionModel to use for rounding

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