addIntersections method

void addIntersections(
  1. Edge e0,
  2. int segIndex0,
  3. Edge e1,
  4. int segIndex1,
)

This method is called by clients of the EdgeIntersector class to test for and add intersections for two segments of the edges being intersected. Note that clients (such as MonotoneChainEdges) may choose not to intersect certain pairs of segments for efficiency reasons.

Implementation

void addIntersections(Edge e0, int segIndex0, Edge e1, int segIndex1) {
  if (e0 == e1 && segIndex0 == segIndex1) return;
  _numTests++;
  Coordinate p00 = e0.getCoordinates()[segIndex0];
  Coordinate p01 = e0.getCoordinates()[segIndex0 + 1];
  Coordinate p10 = e1.getCoordinates()[segIndex1];
  Coordinate p11 = e1.getCoordinates()[segIndex1 + 1];

  _li.computeIntersection(p00, p01, p10, p11);
//if (li.hasIntersection() && li.isProper()) Debug.println(li);
  /**
   *  Always record any non-proper intersections.
   *  If includeProper is true, record any proper intersections as well.
   */
  if (_li.hasIntersection()) {
    if (_recordIsolated) {
      e0.setIsolated(false);
      e1.setIsolated(false);
    }
    //intersectionFound = true;
    _numIntersections++;
    // if the segments are adjacent they have at least one trivial intersection,
    // the shared endpoint.  Don't bother adding it if it is the
    // only intersection.
    if (!isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
      _hasIntersection = true;
      if (_includeProper || !_li.isProper()) {
//Debug.println(li);
        e0.addIntersections(_li, segIndex0, 0);
        e1.addIntersections(_li, segIndex1, 1);
      }
      if (_li.isProper()) {
        _properIntersectionPoint = _li.getIntersection(0).copy();
        _hasProper = true;
        if (_isDoneWhenProperInt) {
          _isDone = true;
        }
        if (!isBoundaryPoint(_li, bdyNodes)) _hasProperInterior = true;
      }
      //if (li.isCollinear())
      //hasCollinear = true;
    }
  }
}