public abstract class LineIntersector extends Object
LineIntersector is an algorithm that can both test whether
two line segments intersect and compute the intersection point(s)
if they do.
There are three possible outcomes when determining whether two line segments intersect:
NO_INTERSECTION - the segments do not intersect
The intersection point(s) may be computed in a precise or non-precise manner. Computing an intersection point precisely involves rounding it via a supplied scale.
LineIntersectors do not perform an initial envelope intersection test to determine if the segments are disjoint. This is because this class is likely to be used in a context where envelope overlap is already known to occur (or be likely).
| Modifier and Type | Field and Description |
|---|---|
static int |
COLLINEAR |
static int |
COLLINEAR_INTERSECTION
Indicates that line segments intersect in a line segment
|
static int |
DO_INTERSECT |
static int |
DONT_INTERSECT
These are deprecated, due to ambiguous naming
|
protected Point[][] |
inputLines |
protected int[][] |
intLineIndex
The indexes of the endpoints of the intersection lines, in order along
the corresponding line
|
protected Point[] |
intPt |
protected boolean |
isProper |
static int |
NO_INTERSECTION
Indicates that line segments do not intersect
|
protected Point |
pa |
protected Point |
pb |
static int |
POINT_INTERSECTION
Indicates that line segments intersect in a single point
|
protected int |
result |
| Constructor and Description |
|---|
LineIntersector() |
LineIntersector(double scale) |
| Modifier and Type | Method and Description |
|---|---|
static double |
computeEdgeDistance(Point p,
Point p0,
Point p1)
Computes the "edge distance" of an intersection point p along a segment.
|
protected abstract int |
computeIntersect(Point p1,
Point p2,
Point q1,
Point q2) |
abstract void |
computeIntersection(Point p,
Point p1,
Point p2)
Compute the intersection of a point p and the line p1-p2.
|
void |
computeIntersection(Point p1,
Point p2,
Point p3,
Point p4)
Computes the intersection of the lines p1-p2 and p3-p4.
|
protected void |
computeIntLineIndex() |
protected void |
computeIntLineIndex(int segmentIndex) |
double |
getEdgeDistance(int segmentIndex,
int intIndex)
Computes the "edge distance" of an intersection point along the specified input line segment.
|
Point |
getEndpoint(int segmentIndex,
int ptIndex)
Gets an endpoint of an input segment.
|
int |
getIndexAlongSegment(int segmentIndex,
int intIndex)
Computes the index (order) of the intIndex'th intersection point in the direction of
a specified input line segment
|
Point |
getIntersection(int intIndex)
Returns the intIndex'th intersection point
|
Point |
getIntersectionAlongSegment(int segmentIndex,
int intIndex)
Computes the intIndex'th intersection point in the direction of
a specified input line segment
|
int |
getIntersectionNum()
Returns the number of intersection points found.
|
double |
getScale() |
boolean |
hasIntersection()
Tests whether the input geometries intersect.
|
protected boolean |
isCollinear() |
protected boolean |
isEndPoint() |
boolean |
isInteriorIntersection()
Tests whether either intersection point is an interior point of one of the input segments.
|
boolean |
isInteriorIntersection(int inputLineIndex)
Tests whether either intersection point is an interior point of the specified input segment.
|
boolean |
isIntersection(Point pt)
Test whether a point is a intersection point of two line segments.
|
boolean |
isProper()
Tests whether an intersection is proper.
|
static double |
nonRobustComputeEdgeDistance(Point p,
Point p1,
Point p2)
This function is non-robust, since it may compute the square of large numbers.
|
void |
setScale(double scale) |
String |
toString() |
public static final int DONT_INTERSECT
public static final int DO_INTERSECT
public static final int COLLINEAR
public static final int NO_INTERSECTION
public static final int POINT_INTERSECTION
public static final int COLLINEAR_INTERSECTION
protected int result
protected Point[][] inputLines
protected Point[] intPt
protected int[][] intLineIndex
protected boolean isProper
protected Point pa
protected Point pb
public LineIntersector()
public LineIntersector(double scale)
public static double computeEdgeDistance(Point p, Point p0, Point p1)
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.
public static double nonRobustComputeEdgeDistance(Point p, Point p1, Point p2)
public abstract void computeIntersection(Point p, Point p1, Point p2)
p.public void computeIntersection(Point p1, Point p2, Point p3, Point p4)
protected void computeIntLineIndex()
protected void computeIntLineIndex(int segmentIndex)
public double getEdgeDistance(int segmentIndex,
int intIndex)
segmentIndex - is 0 or 1intIndex - is 0 or 1public Point getEndpoint(int segmentIndex, int ptIndex)
segmentIndex - the index of the input segment (0 or 1)ptIndex - the index of the endpoint (0 or 1)public int getIndexAlongSegment(int segmentIndex,
int intIndex)
segmentIndex - is 0 or 1intIndex - is 0 or 1public Point getIntersection(int intIndex)
intIndex - is 0 or 1public Point getIntersectionAlongSegment(int segmentIndex, int intIndex)
segmentIndex - is 0 or 1intIndex - is 0 or 1public int getIntersectionNum()
public double getScale()
public boolean hasIntersection()
protected boolean isCollinear()
protected boolean isEndPoint()
public boolean isInteriorIntersection()
true if either intersection point is in the interior of one of the input segmentspublic boolean isInteriorIntersection(int inputLineIndex)
true if either intersection point is in the interior of the input segmentpublic boolean isIntersection(Point pt)
public boolean isProper()
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).
public void setScale(double scale)
Copyright © 2015 Revolution Systems Inc.. All rights reserved.