intersectsToleranceSquare method

bool intersectsToleranceSquare(
  1. Coordinate p0,
  2. Coordinate p1
)

Tests whether the segment p0-p1 intersects the hot pixel tolerance square. Because the tolerance square point set is partially open (along the top and right) the test needs to be more sophisticated than simply checking for any intersection. However, it can take advantage of the fact that the hot pixel edges do not lie on the coordinate grid. It is sufficient to check if any of the following occur:

  • a proper intersection between the segment and any hot pixel edge
  • an intersection between the segment and both the left and bottom hot pixel edges (which detects the case where the segment intersects the bottom left hot pixel corner)
  • an intersection between a segment endpoint and the hot pixel coordinate

@param p0 @param p1 @return

Implementation

bool intersectsToleranceSquare(Coordinate p0, Coordinate p1) {
  bool intersectsLeft = false;
  bool intersectsBottom = false;
  //System.out.println("Hot Pixel: " + WKTWriter.toLineString(corner));
  //System.out.println("Line: " + WKTWriter.toLineString(p0, p1));

  li.computeIntersection(p0, p1, corner[0], corner[1]);
  if (li.isProper()) return true;

  li.computeIntersection(p0, p1, corner[1], corner[2]);
  if (li.isProper()) return true;
  if (li.hasIntersection()) intersectsLeft = true;

  li.computeIntersection(p0, p1, corner[2], corner[3]);
  if (li.isProper()) return true;
  if (li.hasIntersection()) intersectsBottom = true;

  li.computeIntersection(p0, p1, corner[3], corner[0]);
  if (li.isProper()) return true;

  if (intersectsLeft && intersectsBottom) return true;

  if (p0.equals(pt)) return true;
  if (p1.equals(pt)) return true;

  return false;
}