1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

RectangleList: Remove some curly braces

This commit is contained in:
reuk 2025-10-15 18:31:23 +01:00
parent e525e12061
commit 92573ca1ad
No known key found for this signature in database

View file

@ -212,114 +212,110 @@ public:
*/ */
void subtract (const RectangleType rect) void subtract (const RectangleType rect)
{ {
if (auto numRects = rects.size()) const auto numRects = rects.size();
if (numRects == 0)
return;
const auto x1 = rect.getX();
const auto y1 = rect.getY();
const auto x2 = x1 + rect.getWidth();
const auto y2 = y1 + rect.getHeight();
for (int i = numRects; --i >= 0;)
{ {
const auto x1 = rect.getX(); auto& r = rects.getReference (i);
const auto y1 = rect.getY();
const auto x2 = x1 + rect.getWidth();
const auto y2 = y1 + rect.getHeight();
for (int i = numRects; --i >= 0;) const auto rx1 = r.getX();
const auto ry1 = r.getY();
const auto rx2 = rx1 + r.getWidth();
const auto ry2 = ry1 + r.getHeight();
const auto isNotEqual = [&] (const RectangleType newRect)
{ {
auto& r = rects.getReference (i); // When subtracting tiny slices from relatively large rectangles, the
// subtraction may have no effect (due to limited-precision floating point
const auto rx1 = r.getX(); // maths) and the original rectangle may remain unchanged.
const auto ry1 = r.getY(); // We check that any 'new' rectangle has different dimensions to the rectangle
const auto rx2 = rx1 + r.getWidth(); // being tested before adding it to the rects array.
const auto ry2 = ry1 + r.getHeight(); // Integer arithmetic is not susceptible to this problem, so there's no need
// for this additional equality check when working with integral rectangles.
const auto isNotEqual = [&] (const RectangleType newRect) if constexpr (std::is_floating_point_v<ValueType>)
{ {
// When subtracting tiny slices from relatively large rectangles, the return newRect != r;
// subtraction may have no effect (due to limited-precision floating point }
// maths) and the original rectangle may remain unchanged. else
// We check that any 'new' rectangle has different dimensions to the rectangle
// being tested before adding it to the rects array.
// Integer arithmetic is not susceptible to this problem, so there's no need
// for this additional equality check when working with integral rectangles.
if constexpr (std::is_floating_point_v<ValueType>)
{
return newRect != r;
}
else
{
ignoreUnused (newRect);
return true;
}
};
if (rx1 < x2 && x1 < rx2 && ry1 < y2 && y1 < ry2)
{ {
if (rx1 < x1 && x1 < rx2) ignoreUnused (newRect);
{ return true;
if (y1 <= ry1 && ry2 <= y2 && rx2 <= x2) }
{ };
r.setWidth (x1 - rx1);
}
else
{
if (const RectangleType newRect (rx1, ry1, x1 - rx1, ry2 - ry1); isNotEqual (newRect))
{
r.setX (x1);
r.setWidth (rx2 - x1);
rects.insert (++i, newRect); if (! (rx1 < x2 && x1 < rx2 && ry1 < y2 && y1 < ry2))
++i; continue;
}
}
}
else if (rx1 < x2 && x2 < rx2)
{
r.setX (x2);
r.setWidth (rx2 - x2);
if (ry1 < y1 || y2 < ry2 || rx1 < x1) if (rx1 < x1 && x1 < rx2)
{ {
if (const RectangleType newRect (rx1, ry1, x2 - rx1, ry2 - ry1); isNotEqual (newRect)) if (y1 <= ry1 && ry2 <= y2 && rx2 <= x2)
{ {
rects.insert (++i, newRect); r.setWidth (x1 - rx1);
++i; }
} else if (const RectangleType newRect (rx1, ry1, x1 - rx1, ry2 - ry1); isNotEqual (newRect))
} {
} r.setX (x1);
else if (ry1 < y1 && y1 < ry2) r.setWidth (rx2 - x1);
{
if (x1 <= rx1 && rx2 <= x2 && ry2 <= y2)
{
r.setHeight (y1 - ry1);
}
else
{
if (const RectangleType newRect (rx1, ry1, rx2 - rx1, y1 - ry1); isNotEqual (newRect))
{
r.setY (y1);
r.setHeight (ry2 - y1);
rects.insert (++i, newRect); rects.insert (++i, newRect);
++i; ++i;
} }
} }
} else if (rx1 < x2 && x2 < rx2)
else if (ry1 < y2 && y2 < ry2) {
{ r.setX (x2);
r.setY (y2); r.setWidth (rx2 - x2);
r.setHeight (ry2 - y2);
if (rx1 < x1 || x2 < rx2 || ry1 < y1) if (ry1 < y1 || y2 < ry2 || rx1 < x1)
{ {
if (const RectangleType newRect (rx1, ry1, rx2 - rx1, y2 - ry1); isNotEqual (newRect)) if (const RectangleType newRect (rx1, ry1, x2 - rx1, ry2 - ry1); isNotEqual (newRect))
{
rects.insert (++i, newRect);
++i;
}
}
}
else
{ {
rects.remove (i); rects.insert (++i, newRect);
++i;
} }
} }
} }
else if (ry1 < y1 && y1 < ry2)
{
if (x1 <= rx1 && rx2 <= x2 && ry2 <= y2)
{
r.setHeight (y1 - ry1);
}
else if (const RectangleType newRect (rx1, ry1, rx2 - rx1, y1 - ry1); isNotEqual (newRect))
{
r.setY (y1);
r.setHeight (ry2 - y1);
rects.insert (++i, newRect);
++i;
}
}
else if (ry1 < y2 && y2 < ry2)
{
r.setY (y2);
r.setHeight (ry2 - y2);
if (rx1 < x1 || x2 < rx2 || ry1 < y1)
{
if (const RectangleType newRect (rx1, ry1, rx2 - rx1, y2 - ry1); isNotEqual (newRect))
{
rects.insert (++i, newRect);
++i;
}
}
}
else
{
rects.remove (i);
}
} }
} }