isTrivialIntersection method

bool isTrivialIntersection(
  1. SegmentString e0,
  2. int segIndex0,
  3. SegmentString e1,
  4. int segIndex1,
)

A trivial intersection is an apparent self-intersection which in fact is simply the point shared by adjacent line segments. Note that closed edges require a special check for the point shared by the beginning and end segments.

Implementation

bool isTrivialIntersection(
    SegmentString e0, int segIndex0, SegmentString e1, int segIndex1) {
  if (e0 == e1) {
    if (li.getIntersectionNum() == 1) {
      if (isAdjacentSegments(segIndex0, segIndex1)) return true;
      if (e0.isClosed()) {
        int maxSegIndex = e0.size() - 1;
        if ((segIndex0 == 0 && segIndex1 == maxSegIndex) ||
            (segIndex1 == 0 && segIndex0 == maxSegIndex)) {
          return true;
        }
      }
    }
  }
  return false;
}