orientationIndex method
Determines the orientation of a LineSegment relative to this segment. The concept of orientation is specified as follows: Given two line segments A and L,
- A is to the left of a segment L if A lies wholly in the closed half-plane lying to the left of L
- A is to the right of a segment L if A lies wholly in the closed half-plane lying to the right of L
- otherwise, A has indeterminate orientation relative to L. This happens if A is collinear with L or if A crosses the line determined by L.
@param seg the LineSegment to compare
@return 1 if seg
is to the left of this segment
@return -1 if seg
is to the right of this segment
@return 0 if seg
is collinear to or crosses this segment
Implementation
int orientationIndex(LineSegment seg) {
int orient0 = Orientation.index(p0, p1, seg.p0);
int orient1 = Orientation.index(p0, p1, seg.p1);
// this handles the case where the points are L or collinear
if (orient0 >= 0 && orient1 >= 0) return math.max(orient0, orient1);
// this handles the case where the points are R or collinear
if (orient0 <= 0 && orient1 <= 0) return math.max(orient0, orient1);
// points lie on opposite sides ==> indeterminate orientation
return 0;
}