findStabbedSegmentsDE method

void findStabbedSegmentsDE(
  1. Coordinate stabbingRayLeftPt,
  2. DirectedEdge dirEdge,
  3. List stabbedSegments
)

Finds all non-horizontal segments intersecting the stabbing line in the input dirEdge. The stabbing line is the ray to the right of stabbingRayLeftPt.

@param stabbingRayLeftPt the left-hand origin of the stabbing line @param stabbedSegments the current list of {@link DepthSegments} intersecting the stabbing line

Implementation

void findStabbedSegmentsDE(Coordinate stabbingRayLeftPt, DirectedEdge dirEdge,
    List stabbedSegments) {
  List<Coordinate> pts = dirEdge.getEdge().getCoordinates();
  for (int i = 0; i < pts.length - 1; i++) {
    seg.p0 = pts[i];
    seg.p1 = pts[i + 1];
    // ensure segment always points upwards
    if (seg.p0.y > seg.p1.y) seg.reverse();

    // skip segment if it is left of the stabbing line
    double maxx = math.max(seg.p0.x, seg.p1.x);
    if (maxx < stabbingRayLeftPt.x) continue;

    // skip horizontal segments (there will be a non-horizontal one carrying the same depth info
    if (seg.isHorizontal()) continue;

    // skip if segment is above or below stabbing line
    if (stabbingRayLeftPt.y < seg.p0.y || stabbingRayLeftPt.y > seg.p1.y)
      continue;

    // skip if stabbing ray is right of the segment
    if (Orientation.index(seg.p0, seg.p1, stabbingRayLeftPt) ==
        Orientation.RIGHT) continue;

    // stabbing line cuts this segment, so record it
    int depth = dirEdge.getDepth(Position.LEFT);
    // if segment direction was flipped, use RHS depth instead
    if (!seg.p0.equals(pts[i])) depth = dirEdge.getDepth(Position.RIGHT);
    DepthSegment ds = new DepthSegment(seg, depth);
    stabbedSegments.add(ds);
  }
}