intersectsRectangle method

bool intersectsRectangle(
  1. Rectangle<num> r,
  2. bool bias
)

Returns a fast computation if the line intersects the rectangle or bias if there is no fast way to compute the intersection.

@param r retangle to test @param bias the result if no fast computation is possible @return either the fast and correct result or the bias (which might be wrong).

Implementation

bool intersectsRectangle(Rectangle r, bool bias) {
  int codeStart = code(r, start);
  int codeEnd = code(r, end);

  if (0 == (codeStart | codeEnd)) {
    // both points are inside, trivial case
    return true;
  } else if (0 != (codeStart & codeEnd)) {
    // both points are either below, above, left or right of the box, no intersection
    return false;
  }
  return bias;
}