diff --git a/modules/juce_graphics/geometry/juce_Line.h b/modules/juce_graphics/geometry/juce_Line.h index cf1b9646a3..95665c5235 100644 --- a/modules/juce_graphics/geometry/juce_Line.h +++ b/modules/juce_graphics/geometry/juce_Line.h @@ -153,6 +153,18 @@ public: bool operator!= (const Line& other) const noexcept { return start != other.start || end != other.end; } //============================================================================== + /** Finds the intersection between two lines. + + @param line the line to intersect with + @returns the point at which the lines intersect, even if this lies beyond the end of the lines + */ + Point getIntersection (const Line& line) const noexcept + { + Point p; + findIntersection (start, end, line.start, line.end, p); + return p; + } + /** Finds the intersection between two lines. @param line the other line @@ -170,16 +182,11 @@ public: return findIntersection (start, end, line.start, line.end, intersection); } - /** Finds the intersection between two lines. - - @param line the line to intersect with - @returns the point at which the lines intersect, even if this lies beyond the end of the lines - */ - Point getIntersection (const Line& line) const noexcept + /** Returns true if this line intersects another. */ + bool intersects (const Line& other) const noexcept { - Point p; - findIntersection (start, end, line.start, line.end, p); - return p; + Point ignored; + return findIntersection (start, end, other.start, other.end, ignored); } //============================================================================== diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index 7dc0e736be..4c38837f37 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -563,6 +563,16 @@ public: && other.w > ValueType() && other.h > ValueType(); } + /** Returns true if any part of the given line lies inside this rectangle. */ + bool intersects (const Line& line) const noexcept + { + return contains (line.getStart()) || contains (line.getEnd()) + || line.intersects (Line (getTopLeft(), getTopRight())) + || line.intersects (Line (getTopRight(), getBottomRight())) + || line.intersects (Line (getBottomRight(), getBottomLeft())) + || line.intersects (Line (getBottomLeft(), getTopLeft())); + } + /** Returns the region that is the overlap between this and another rectangle. If the two rectangles don't overlap, the rectangle returned will be empty. */