41template <
typename ValueType>
71 : rects (std::move (
other.rects))
78 rects = std::move (
other.rects);
124 for (
int j = rects.size(); --
j >= 0;)
126 auto&
ourRect = rects.getReference (
j);
132 else if (!
ourRect.reduceIfPartlyContainedIn (rect))
152 rects.addArray (r.rects);
167 void add (ValueType x, ValueType y, ValueType width, ValueType height)
195 for (
auto& r :
other)
208 const auto x1 = rect.
getX();
209 const auto y1 = rect.
getY();
210 const auto x2 = x1 + rect.
getWidth();
215 auto& r = rects.getReference (i);
217 const auto rx1 = r.getX();
218 const auto ry1 = r.getY();
219 const auto rx2 = rx1 + r.getWidth();
220 const auto ry2 = ry1 + r.getHeight();
231 if constexpr (std::is_floating_point_v<ValueType>)
242 if (rx1 < x2 && x1 < rx2 && ry1 < y2 &&
y1 < ry2)
244 if (rx1 < x1 && x1 < rx2)
246 if (
y1 <= ry1 && ry2 <= y2 && rx2 <= x2)
248 r.setWidth (x1 - rx1);
255 r.setWidth (rx2 - x1);
262 else if (rx1 < x2 && x2 < rx2)
265 r.setWidth (rx2 - x2);
267 if (ry1 <
y1 || y2 < ry2 || rx1 < x1)
276 else if (ry1 <
y1 &&
y1 < ry2)
278 if (x1 <= rx1 && rx2 <= x2 && ry2 <= y2)
280 r.setHeight (
y1 - ry1);
287 r.setHeight (ry2 -
y1);
294 else if (ry1 < y2 && y2 < ry2)
297 r.setHeight (ry2 - y2);
299 if (rx1 < x1 || x2 < rx2 || ry1 <
y1)
358 for (
int i = rects.size(); --i >= 0;)
360 auto& r = rects.getReference (i);
381 template <
typename OtherValueType>
389 for (
auto& rect : rects)
391 for (
auto& r :
other)
395 if (rect.intersectRectangle (
clipped))
443 for (
auto& r : rects)
444 if (r.contains (point))
466 if (rects.size() > 1)
470 for (
auto& rect : rects)
494 for (
auto& r : rects)
506 for (
auto& r : rects)
507 if (
other.intersectsRectangle (r))
520 auto& r = rects.getReference (0);
522 if (rects.size() == 1)
525 auto minX = r.getX();
526 auto minY = r.getY();
527 auto maxX =
minX + r.getWidth();
528 auto maxY =
minY + r.getHeight();
530 for (
int i = rects.size(); --i > 0;)
532 auto&
r2 = rects.getReference (i);
536 maxX =
jmax (maxX,
r2.getRight());
537 maxY =
jmax (maxY,
r2.getBottom());
551 for (
int i = 0; i < rects.size() - 1; ++i)
553 auto& r = rects.getReference (i);
556 auto rx2 = rx1 + r.getWidth();
557 auto ry2 = ry1 + r.getHeight();
559 for (
int j = rects.size(); --
j > i;)
561 auto&
r2 = rects.getReference (
j);
573 r.setHeight (
jry1 - ry1);
581 r.setHeight (
jry2 - ry1);
588 r2.setHeight (ry1 -
jry1);
595 r2.setHeight (ry2 -
jry1);
604 for (
int i = 0; i < rects.size() - 1; ++i)
606 auto& r = rects.getReference (i);
608 for (
int j = rects.size(); --
j > i;)
610 if (r.enlargeIfAdjacent (rects.getReference (
j)))
623 for (
auto& r : rects)
634 template <
typename ScaleType>
637 for (
auto& r : rects)
647 for (
auto& r : rects)
648 r = r.transformedBy (transform);
657 for (
auto& r : rects)
Holds a resizable array of primitive or copy-by-value objects.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
void addRectangle(float x, float y, float width, float height)
Adds a rectangle to the path.
A pair of (x, y) coordinates.
Maintains a set of rectangles as a complex region.
bool containsPoint(ValueType x, ValueType y) const noexcept
Checks whether the region contains a given point.
RectangleType getRectangle(int index) const noexcept
Returns one of the rectangles at a particular index.
bool clipTo(const RectangleList< OtherValueType > &other)
Removes any areas of the region that lie outside a given rectangle list.
void clear()
Removes all rectangles to leave an empty region.
RectangleType getBounds() const noexcept
Returns the smallest rectangle that can enclose the whole of this region.
void add(ValueType x, ValueType y, ValueType width, ValueType height)
Merges a new rectangle into the list.
RectangleList(RectangleList &&other) noexcept
Move constructor.
void addWithoutMerging(RectangleType rect)
Dumbly adds a rectangle to the list without checking for overlaps.
void offsetAll(ValueType dx, ValueType dy) noexcept
Adds an x and y value to all the coordinates.
void add(const RectangleList &other)
Merges another rectangle list into this one.
Path toPath() const
Creates a Path object to represent this region.
bool subtract(const RectangleList &otherList)
Removes all areas in another RectangleList from this one.
void offsetAll(Point< ValueType > offset) noexcept
Adds an x and y value to all the coordinates.
bool intersectsRectangle(RectangleType rectangleToCheck) const noexcept
Checks whether the region contains any part of a given rectangle.
RectangleList & operator=(const RectangleList &other)
Copies this list from another one.
bool containsRectangle(RectangleType rectangleToCheck) const
Checks whether the region contains the whole of a given rectangle.
void scaleAll(ScaleType scaleFactor) noexcept
Scales all the coordinates.
RectangleList()=default
Creates an empty RectangleList.
bool intersects(const RectangleList &other) const noexcept
Checks whether this region intersects any part of another one.
bool clipTo(RectangleType rect)
Removes any areas of the region that lie outside a given rectangle.
const RectangleType * begin() const noexcept
Standard method for iterating the rectangles in the list.
bool containsPoint(Point< ValueType > point) const noexcept
Checks whether the region contains a given point.
const RectangleType * end() const noexcept
Standard method for iterating the rectangles in the list.
RectangleList(const RectangleList &other)
Creates a copy of another list.
RectangleList(RectangleType rect)
Creates a list containing just one rectangle.
void add(RectangleType rect)
Merges a new rectangle into the list.
int getNumRectangles() const noexcept
Returns the number of rectangles in the list.
void subtract(const RectangleType rect)
Removes a rectangular region from the list.
bool isEmpty() const noexcept
Returns true if the region is empty.
void swapWith(RectangleList &otherList) noexcept
Swaps the contents of this and another list.
void ensureStorageAllocated(int minNumRectangles)
Increases the internal storage to hold a minimum number of rectangles.
void consolidate()
Optimises the list into a minimum number of constituent rectangles.
bool getIntersectionWith(RectangleType rect, RectangleList &destRegion) const
Creates a region which is the result of clipping this one to a given rectangle.
void transformAll(const AffineTransform &transform) noexcept
Applies a transform to all the rectangles.
Manages a rectangle and allows geometric operations to be performed on it.
bool intersects(Rectangle other) const noexcept
Returns true if any part of another rectangle overlaps this one.
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Returns true if this coordinate is inside the rectangle.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
bool isFinite() const noexcept
Returns true if the rectangle's values are all finite numbers, i.e.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
bool isEmpty() const noexcept
Returns true if the rectangle's width or height are zero or less.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
bool intersectRectangle(ValueType &otherX, ValueType &otherY, ValueType &otherW, ValueType &otherH) const noexcept
Clips a set of rectangle coordinates so that they lie only within this one.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
void ignoreUnused(Types &&...) noexcept
Handy function for avoiding unused variables warning.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...