public static Point getIntersectionPoint(Line2D aSegment, Rectangle aRectangle) {

    if (segmentOutsideRectangle(aRectangle, aSegment)) {
      throw new IllegalArgumentException("Segment " + toString(aSegment) + " lies out of rectangle " + aRectangle + " or intersects more than one bound");
    }

    if (segmentInsideRectangle(aRectangle, aSegment)) {
      return null;
    }

    Line2D[] bounds = new Line2D[4];
    bounds[0] = getTopOf(aRectangle);
    bounds[1] = getRightOf(aRectangle);
    bounds[2] = getBottomOf(aRectangle);
    bounds[3] = getLeftOf(aRectangle);

    for (Line2D bound : bounds) {
      if (bound.intersectsLine(aSegment)) {
        return getIntersectionPoint(aSegment, bound);
      }
    }

    return null;
  }
public static Point getIntersectionPoint(Line2D aSegment, Rectangle aRectangle)