isLineSegmentContainedInBoundary method

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

Tests if a line segment is contained in the boundary of the target rectangle. @param p0 an endpoint of the segment @param p1 an endpoint of the segment @return true if the line segment is contained in the boundary

Implementation

bool isLineSegmentContainedInBoundary(Coordinate p0, Coordinate p1) {
  if (p0.equals(p1)) return isPointContainedInBoundaryCoord(p0);

  // we already know that the segment is contained in the rectangle envelope
  if (p0.x == p1.x) {
    if (p0.x == rectEnv.getMinX() || p0.x == rectEnv.getMaxX()) return true;
  } else if (p0.y == p1.y) {
    if (p0.y == rectEnv.getMinY() || p0.y == rectEnv.getMaxY()) return true;
  }
  /**
   * Either
   *   both x and y values are different
   * or
   *   one of x and y are the same, but the other ordinate is not the same as a boundary ordinate
   *
   * In either case, the segment is not wholely in the boundary
   */
  return false;
}