25 #ifndef JUCE_RECTANGLELIST_H_INCLUDED 26 #define JUCE_RECTANGLELIST_H_INCLUDED 39 template <
typename ValueType>
67 #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS 108 void add (
const RectangleType& rect)
114 if (rects.size() == 0)
120 bool anyOverlaps =
false;
122 for (
int j = rects.size(); --j >= 0;)
124 RectangleType& ourRect = rects.getReference (j);
135 if (anyOverlaps && rects.size() > 0)
139 for (
int i = rects.size(); --i >= 0;)
141 const RectangleType& ourRect = rects.getReference (i);
147 if (r.rects.size() == 0)
152 rects.addArray (r.rects);
167 void add (ValueType x, ValueType y, ValueType
width, ValueType height)
169 add (RectangleType (x, y, width, height));
195 for (
const RectangleType* r = other.
begin(), *
const e = other.
end(); r != e; ++r)
206 const int originalNumRects = rects.size();
208 if (originalNumRects > 0)
210 const ValueType x1 = rect.
getX();
211 const ValueType y1 = rect.
getY();
212 const ValueType x2 = x1 + rect.
getWidth();
213 const ValueType y2 = y1 + rect.
getHeight();
217 RectangleType& r = rects.getReference (i);
219 const ValueType rx1 = r.
getX();
220 const ValueType ry1 = r.
getY();
221 const ValueType rx2 = rx1 + r.
getWidth();
222 const ValueType ry2 = ry1 + r.
getHeight();
224 if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
226 if (x1 > rx1 && x1 < rx2)
228 if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
237 rects.insert (++i, RectangleType (rx1, ry1, x1 - rx1, ry2 - ry1));
241 else if (x2 > rx1 && x2 < rx2)
246 if (y1 > ry1 || y2 < ry2 || x1 > rx1)
248 rects.insert (++i, RectangleType (rx1, ry1, x2 - rx1, ry2 - ry1));
252 else if (y1 > ry1 && y1 < ry2)
254 if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
263 rects.insert (++i, RectangleType (rx1, ry1, rx2 - rx1, y1 - ry1));
267 else if (y2 > ry1 && y2 < ry2)
272 if (x1 > rx1 || x2 < rx2 || y1 > ry1)
274 rects.insert (++i, RectangleType (rx1, ry1, rx2 - rx1, y2 - ry1));
296 for (
int i = otherList.rects.size(); --i >= 0 && rects.size() > 0;)
297 subtract (otherList.rects.getReference (i));
299 return rects.size() > 0;
315 bool notEmpty =
false;
323 for (
int i = rects.size(); --i >= 0;)
325 RectangleType& r = rects.getReference (i);
346 template <
typename OtherValueType>
349 if (rects.size() == 0)
354 for (
int j = 0; j < rects.size(); ++j)
356 const RectangleType& rect = rects.getReference (j);
360 RectangleType clipped (r->template toType<ValueType>());
363 result.rects.add (clipped);
388 for (
int i = rects.size(); --i >= 0;)
390 RectangleType r (rects.getReference (i));
393 destRegion.rects.add (r);
397 return destRegion.rects.size() > 0;
407 rects.swapWith (otherList.rects);
416 for (
const RectangleType* r = rects.begin(), *
const e = rects.end(); r != e; ++r)
417 if (r->contains (point))
439 if (rects.size() > 1)
443 for (
int i = rects.size(); --i >= 0;)
445 r.
subtract (rects.getReference (i));
447 if (r.rects.size() == 0)
451 else if (rects.size() > 0)
453 return rects.getReference (0).contains (rectangleToCheck);
467 for (
const RectangleType* r = rects.begin(), *
const e = rects.end(); r != e; ++r)
468 if (r->intersects (rectangleToCheck))
480 for (
const RectangleType* r = rects.begin(), *
const e = rects.end(); r != e; ++r)
481 if (other.intersectsRectangle (*r))
491 if (rects.size() <= 1)
493 if (rects.size() == 0)
496 return rects.getReference (0);
499 const RectangleType& r = rects.getReference (0);
501 ValueType minX = r.
getX();
502 ValueType minY = r.
getY();
503 ValueType maxX = minX + r.
getWidth();
506 for (
int i = rects.size(); --i > 0;)
508 const RectangleType& r2 = rects.getReference (i);
529 RectangleType& r = rects.getReference (i);
530 const ValueType rx1 = r.
getX();
531 const ValueType ry1 = r.
getY();
532 const ValueType rx2 = rx1 + r.
getWidth();
533 const ValueType ry2 = ry1 + r.
getHeight();
535 for (
int j = rects.size(); --j > i;)
537 RectangleType& r2 = rects.getReference (j);
538 const ValueType jrx1 = r2.
getX();
539 const ValueType jry1 = r2.
getY();
540 const ValueType jrx2 = jrx1 + r2.
getWidth();
541 const ValueType jry2 = jry1 + r2.
getHeight();
545 if (jrx1 == rx2 || jrx2 == rx1)
547 if (jry1 > ry1 && jry1 < ry2)
550 rects.add (RectangleType (rx1, jry1, rx2 - rx1, ry2 - jry1));
555 if (jry2 > ry1 && jry2 < ry2)
558 rects.add (RectangleType (rx1, jry2, rx2 - rx1, ry2 - jry2));
562 else if (ry1 > jry1 && ry1 < jry2)
565 rects.add (RectangleType (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
569 else if (ry2 > jry1 && ry2 < jry2)
572 rects.add (RectangleType (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
580 for (
int i = 0; i < rects.size() - 1; ++i)
582 RectangleType& r = rects.getReference (i);
584 for (
int j = rects.size(); --j > i;)
599 for (RectangleType* r = rects.begin(), *
const e = rects.end(); r != e; ++r)
610 template <
typename ScaleType>
613 for (RectangleType* r = rects.begin(), *
const e = rects.end(); r != e; ++r)
623 for (RectangleType* r = rects.begin(), *
const e = rects.end(); r != e; ++r)
624 *r = r->transformedBy (transform);
633 for (
int i = 0; i < rects.size(); ++i)
653 rects.ensureStorageAllocated (minNumRectangles);
662 #endif // JUCE_RECTANGLELIST_H_INCLUDED ValueType getWidth() const noexcept
Definition: juce_Rectangle.h:113
bool clipTo(const RectangleList< OtherValueType > &other)
Definition: juce_RectangleList.h:347
void subtract(const RectangleType &rect)
Definition: juce_RectangleList.h:204
ValueType getRight() const noexcept
Definition: juce_Rectangle.h:119
void consolidate()
Definition: juce_RectangleList.h:525
void setHeight(ValueType newHeight) noexcept
Definition: juce_Rectangle.h:184
RectangleList & operator=(const RectangleList &other)
Definition: juce_RectangleList.h:61
void offsetAll(Point< ValueType > offset) noexcept
Definition: juce_RectangleList.h:597
#define noexcept
Definition: juce_CompilerSupport.h:141
bool reduceIfPartlyContainedIn(const Rectangle &other) noexcept
Definition: juce_Rectangle.h:708
ValueType getX() const noexcept
Definition: juce_Rectangle.h:107
bool intersects(const RectangleList &other) const noexcept
Definition: juce_RectangleList.h:478
void ensureStorageAllocated(int minNumRectangles)
Definition: juce_RectangleList.h:651
ValueType getHeight() const noexcept
Definition: juce_Rectangle.h:116
Type jmin(const Type a, const Type b)
Definition: juce_core.h:113
void offsetAll(ValueType dx, ValueType dy) noexcept
Definition: juce_RectangleList.h:604
Definition: juce_RectangleList.h:40
RectangleList() noexcept
Definition: juce_RectangleList.h:47
bool intersects(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:586
bool intersectsRectangle(const RectangleType &rectangleToCheck) const noexcept
Definition: juce_RectangleList.h:465
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Definition: juce_Rectangle.h:549
Definition: juce_Point.h:39
void clear()
Definition: juce_RectangleList.h:94
Rectangle< ValueType > RectangleType
Definition: juce_RectangleList.h:43
void addWithoutMerging(const RectangleType &rect)
Definition: juce_RectangleList.h:180
void add(ValueType x, ValueType y, ValueType width, ValueType height)
Definition: juce_RectangleList.h:167
void transformAll(const AffineTransform &transform) noexcept
Definition: juce_RectangleList.h:621
ValueType getBottom() const noexcept
Definition: juce_Rectangle.h:122
RectangleType getRectangle(int index) const noexcept
Definition: juce_RectangleList.h:90
void setX(ValueType newX) noexcept
Definition: juce_Rectangle.h:175
RectangleList(const RectangleType &rect)
Definition: juce_RectangleList.h:55
Definition: juce_Rectangle.h:36
void addRectangle(float x, float y, float width, float height)
Definition: juce_Path.cpp:399
Definition: juce_Path.h:62
const RectangleType * begin() const noexcept
Definition: juce_RectangleList.h:641
bool containsRectangle(const RectangleType &rectangleToCheck) const
Definition: juce_RectangleList.h:437
bool isFinite() const noexcept
Definition: juce_Rectangle.h:104
void add(const RectangleList &other)
Definition: juce_RectangleList.h:193
void setY(ValueType newY) noexcept
Definition: juce_Rectangle.h:178
int getNumRectangles() const noexcept
Definition: juce_RectangleList.h:85
bool isEmpty() const noexcept
Definition: juce_RectangleList.h:82
bool intersectRectangle(ValueType &otherX, ValueType &otherY, ValueType &otherW, ValueType &otherH) const noexcept
Definition: juce_Rectangle.h:626
Type jmax(const Type a, const Type b)
Definition: juce_core.h:101
bool enlargeIfAdjacent(const Rectangle &other) noexcept
Definition: juce_Rectangle.h:679
const RectangleType * end() const noexcept
Definition: juce_RectangleList.h:643
void add(const RectangleType &rect)
Definition: juce_RectangleList.h:108
RectangleType getBounds() const noexcept
Definition: juce_RectangleList.h:489
png_const_structrp png_const_inforp int png_fixed_point * width
Definition: juce_PNGLoader.cpp:2339
bool subtract(const RectangleList &otherList)
Definition: juce_RectangleList.h:294
Path toPath() const
Definition: juce_RectangleList.h:629
Definition: juce_Array.h:60
void swapWith(RectangleList &otherList) noexcept
Definition: juce_RectangleList.h:405
ValueType getY() const noexcept
Definition: juce_Rectangle.h:110
void setWidth(ValueType newWidth) noexcept
Definition: juce_Rectangle.h:181
bool clipTo(const RectangleType &rect)
Definition: juce_RectangleList.h:311
bool containsPoint(Point< ValueType > point) const noexcept
Definition: juce_RectangleList.h:414
void scaleAll(ScaleType scaleFactor) noexcept
Definition: juce_RectangleList.h:611
bool getIntersectionWith(const RectangleType &rect, RectangleList &destRegion) const
Definition: juce_RectangleList.h:380
RectangleList(const RectangleList &other)
Definition: juce_RectangleList.h:50
bool containsPoint(ValueType x, ValueType y) const noexcept
Definition: juce_RectangleList.h:426
bool isEmpty() const noexcept
Definition: juce_Rectangle.h:101