JUCE
|
Maintains a set of rectangles as a complex region. More...
Public Types | |
using | RectangleType = Rectangle< ValueType > |
Public Member Functions | |
RectangleList ()=default | |
Creates an empty RectangleList. More... | |
RectangleList (const RectangleList &other) | |
Creates a copy of another list. More... | |
RectangleList (RectangleType rect) | |
Creates a list containing just one rectangle. More... | |
RectangleList & | operator= (const RectangleList &other) |
Copies this list from another one. More... | |
RectangleList (RectangleList &&other) noexcept | |
Move constructor. More... | |
RectangleList & | operator= (RectangleList &&other) noexcept |
Move assignment operator. More... | |
bool | isEmpty () const noexcept |
Returns true if the region is empty. More... | |
int | getNumRectangles () const noexcept |
Returns the number of rectangles in the list. More... | |
RectangleType | getRectangle (int index) const noexcept |
Returns one of the rectangles at a particular index. More... | |
void | clear () |
Removes all rectangles to leave an empty region. More... | |
void | add (RectangleType rect) |
Merges a new rectangle into the list. More... | |
void | add (ValueType x, ValueType y, ValueType width, ValueType height) |
Merges a new rectangle into the list. More... | |
void | addWithoutMerging (RectangleType rect) |
Dumbly adds a rectangle to the list without checking for overlaps. More... | |
void | add (const RectangleList &other) |
Merges another rectangle list into this one. More... | |
void | subtract (RectangleType rect) |
Removes a rectangular region from the list. More... | |
bool | subtract (const RectangleList &otherList) |
Removes all areas in another RectangleList from this one. More... | |
bool | clipTo (RectangleType rect) |
Removes any areas of the region that lie outside a given rectangle. More... | |
template<typename OtherValueType > | |
bool | clipTo (const RectangleList< OtherValueType > &other) |
Removes any areas of the region that lie outside a given rectangle list. More... | |
bool | getIntersectionWith (RectangleType rect, RectangleList &destRegion) const |
Creates a region which is the result of clipping this one to a given rectangle. More... | |
void | swapWith (RectangleList &otherList) noexcept |
Swaps the contents of this and another list. More... | |
bool | containsPoint (Point< ValueType > point) const noexcept |
Checks whether the region contains a given point. More... | |
bool | containsPoint (ValueType x, ValueType y) const noexcept |
Checks whether the region contains a given point. More... | |
bool | containsRectangle (RectangleType rectangleToCheck) const |
Checks whether the region contains the whole of a given rectangle. More... | |
bool | intersectsRectangle (RectangleType rectangleToCheck) const noexcept |
Checks whether the region contains any part of a given rectangle. More... | |
bool | intersects (const RectangleList &other) const noexcept |
Checks whether this region intersects any part of another one. More... | |
RectangleType | getBounds () const noexcept |
Returns the smallest rectangle that can enclose the whole of this region. More... | |
void | consolidate () |
Optimises the list into a minimum number of constituent rectangles. More... | |
void | offsetAll (Point< ValueType > offset) noexcept |
Adds an x and y value to all the coordinates. More... | |
void | offsetAll (ValueType dx, ValueType dy) noexcept |
Adds an x and y value to all the coordinates. More... | |
template<typename ScaleType > | |
void | scaleAll (ScaleType scaleFactor) noexcept |
Scales all the coordinates. More... | |
void | transformAll (const AffineTransform &transform) noexcept |
Applies a transform to all the rectangles. More... | |
Path | toPath () const |
Creates a Path object to represent this region. More... | |
const RectangleType * | begin () const noexcept |
Standard method for iterating the rectangles in the list. More... | |
const RectangleType * | end () const noexcept |
Standard method for iterating the rectangles in the list. More... | |
void | ensureStorageAllocated (int minNumRectangles) |
Increases the internal storage to hold a minimum number of rectangles. More... | |
Maintains a set of rectangles as a complex region.
This class allows a set of rectangles to be treated as a solid shape, and can add and remove rectangular sections of it, and simplify overlapping or adjacent rectangles.
using RectangleList< ValueType >::RectangleType = Rectangle<ValueType> |
|
default |
Creates an empty RectangleList.
RectangleList< ValueType >::RectangleList | ( | const RectangleList< ValueType > & | other | ) |
Creates a copy of another list.
RectangleList< ValueType >::RectangleList | ( | RectangleType | rect | ) |
Creates a list containing just one rectangle.
References RectangleList< ValueType >::addWithoutMerging().
|
noexcept |
Move constructor.
RectangleList& RectangleList< ValueType >::operator= | ( | const RectangleList< ValueType > & | other | ) |
Copies this list from another one.
|
noexcept |
Move assignment operator.
|
noexcept |
Returns true if the region is empty.
Referenced by RectangleList< ValueType >::add(), RectangleList< ValueType >::clipTo(), RectangleList< ValueType >::containsRectangle(), RectangleList< ValueType >::getBounds(), RectangleList< ValueType >::getIntersectionWith(), and RectangleList< ValueType >::subtract().
|
noexcept |
Returns the number of rectangles in the list.
|
noexcept |
Returns one of the rectangles at a particular index.
References gl::index.
void RectangleList< ValueType >::clear | ( | ) |
Removes all rectangles to leave an empty region.
Referenced by RectangleList< ValueType >::clipTo(), and RectangleList< ValueType >::getIntersectionWith().
void RectangleList< ValueType >::add | ( | RectangleType | rect | ) |
Merges a new rectangle into the list.
The rectangle being added will first be clipped to remove any parts of it that overlap existing rectangles in the list, and adjacent rectangles will be merged into it.
The rectangle can have any size and may be empty, but if it's floating point then it's expected to not contain any INF values.
References Rectangle< ValueType >::contains(), Rectangle< ValueType >::intersects(), Rectangle< ValueType >::isEmpty(), RectangleList< ValueType >::isEmpty(), Rectangle< ValueType >::isFinite(), gl::j, jassert, and gl::r.
Referenced by RectangleList< ValueType >::add().
void RectangleList< ValueType >::add | ( | ValueType | x, |
ValueType | y, | ||
ValueType | width, | ||
ValueType | height | ||
) |
Merges a new rectangle into the list.
The rectangle being added will first be clipped to remove any parts of it that overlap existing rectangles in the list.
References RectangleList< ValueType >::add(), gl::height, gl::width, gl::x, and gl::y.
void RectangleList< ValueType >::addWithoutMerging | ( | RectangleType | rect | ) |
Dumbly adds a rectangle to the list without checking for overlaps.
This simply adds the rectangle to the end, it doesn't merge it or remove any overlapping bits.
The rectangle can have any size and may be empty, but if it's floating point then it's expected to not contain any INF values.
References Rectangle< ValueType >::isEmpty(), Rectangle< ValueType >::isFinite(), and jassert.
Referenced by RectangleList< ValueType >::RectangleList().
void RectangleList< ValueType >::add | ( | const RectangleList< ValueType > & | other | ) |
Merges another rectangle list into this one.
Any overlaps between the two lists will be clipped, so that the result is the union of both lists.
References RectangleList< ValueType >::add(), and gl::r.
void RectangleList< ValueType >::subtract | ( | RectangleType | rect | ) |
Removes a rectangular region from the list.
Any rectangles in the list which overlap this will be clipped and subdivided if necessary.
References Rectangle< ValueType >::getHeight(), Rectangle< ValueType >::getWidth(), Rectangle< ValueType >::getX(), Rectangle< ValueType >::getY(), gl::r, gl::x1, gl::x2, gl::y1, and gl::y2.
Referenced by RectangleList< ValueType >::subtract().
bool RectangleList< ValueType >::subtract | ( | const RectangleList< ValueType > & | otherList | ) |
Removes all areas in another RectangleList from this one.
Any rectangles in the list which overlap this will be clipped and subdivided if necessary.
References RectangleList< ValueType >::isEmpty(), gl::r, and RectangleList< ValueType >::subtract().
bool RectangleList< ValueType >::clipTo | ( | RectangleType | rect | ) |
Removes any areas of the region that lie outside a given rectangle.
Any rectangles in the list which overlap this will be clipped and subdivided if necessary.
Returns true if the resulting region is not empty, false if it is empty.
References RectangleList< ValueType >::clear(), Rectangle< ValueType >::intersectRectangle(), Rectangle< ValueType >::isEmpty(), Rectangle< ValueType >::isFinite(), jassert, and gl::r.
bool RectangleList< ValueType >::clipTo | ( | const RectangleList< OtherValueType > & | other | ) |
Removes any areas of the region that lie outside a given rectangle list.
Any rectangles in this object which overlap the specified list will be clipped and subdivided if necessary.
Returns true if the resulting region is not empty, false if it is empty.
References RectangleList< ValueType >::isEmpty(), gl::r, gl::result, and RectangleList< ValueType >::swapWith().
bool RectangleList< ValueType >::getIntersectionWith | ( | RectangleType | rect, |
RectangleList< ValueType > & | destRegion | ||
) | const |
Creates a region which is the result of clipping this one to a given rectangle.
Unlike the other clipTo method, this one doesn't affect this object - it puts the resulting region into the list whose reference is passed-in.
Returns true if the resulting region is not empty, false if it is empty.
References RectangleList< ValueType >::clear(), Rectangle< ValueType >::intersectRectangle(), Rectangle< ValueType >::isEmpty(), RectangleList< ValueType >::isEmpty(), Rectangle< ValueType >::isFinite(), jassert, and gl::r.
|
noexcept |
Swaps the contents of this and another list.
This swaps their internal pointers, so is hugely faster than using copy-by-value to swap them.
Referenced by RectangleList< ValueType >::clipTo().
|
noexcept |
Checks whether the region contains a given point.
References gl::r.
Referenced by RectangleList< ValueType >::containsPoint().
|
noexcept |
Checks whether the region contains a given point.
References RectangleList< ValueType >::containsPoint(), gl::x, and gl::y.
bool RectangleList< ValueType >::containsRectangle | ( | RectangleType | rectangleToCheck | ) | const |
Checks whether the region contains the whole of a given rectangle.
References RectangleList< ValueType >::isEmpty(), and gl::r.
|
noexcept |
Checks whether the region contains any part of a given rectangle.
References gl::r.
|
noexcept |
Checks whether this region intersects any part of another one.
References gl::r.
|
noexcept |
void RectangleList< ValueType >::consolidate | ( | ) |
|
noexcept |
Adds an x and y value to all the coordinates.
References gl::offset, and gl::r.
Referenced by RectangleList< ValueType >::offsetAll().
|
noexcept |
Adds an x and y value to all the coordinates.
References RectangleList< ValueType >::offsetAll().
|
noexcept |
Scales all the coordinates.
References gl::r, and gl::scaleFactor.
|
noexcept |
Applies a transform to all the rectangles.
Obviously this will create a mess if the transform involves any rotation or skewing.
References gl::r, and gl::transform.
Path RectangleList< ValueType >::toPath | ( | ) | const |
|
noexcept |
Standard method for iterating the rectangles in the list.
|
noexcept |
Standard method for iterating the rectangles in the list.
void RectangleList< ValueType >::ensureStorageAllocated | ( | int | minNumRectangles | ) |
Increases the internal storage to hold a minimum number of rectangles.
Calling this before adding a large number of rectangles means that the array won't have to keep dynamically resizing itself as the elements are added, and it'll therefore be more efficient.