|
|
|
@@ -688,22 +688,12 @@ public: |
|
|
|
*/
|
|
|
|
Rectangle<int> getSmallestIntegerContainer() const noexcept
|
|
|
|
{
|
|
|
|
return getSmallestIntegerContainerWithType<int>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the smallest integer-aligned rectangle that completely contains this one.
|
|
|
|
This is only relevent for floating-point rectangles, of course.
|
|
|
|
@see toFloat()
|
|
|
|
*/
|
|
|
|
template <typename IntType>
|
|
|
|
Rectangle<IntType> getSmallestIntegerContainerWithType() const noexcept
|
|
|
|
{
|
|
|
|
const IntType x1 = static_cast<IntType> (std::floor (pos.x));
|
|
|
|
const IntType y1 = static_cast<IntType> (std::floor (pos.y));
|
|
|
|
const IntType x2 = static_cast<IntType> (std::ceil (pos.x + w));
|
|
|
|
const IntType y2 = static_cast<IntType> (std::ceil (pos.y + h));
|
|
|
|
const int x1 = floorAsInt (pos.x);
|
|
|
|
const int y1 = floorAsInt (pos.y);
|
|
|
|
const int x2 = ceilAsInt (pos.x + w);
|
|
|
|
const int y2 = ceilAsInt (pos.y + h);
|
|
|
|
|
|
|
|
return Rectangle<IntType> (x1, y1, x2 - x1, y2 - y1);
|
|
|
|
return Rectangle<int> (x1, y1, x2 - x1, y2 - y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Casts this rectangle to a Rectangle<float>.
|
|
|
|
@@ -828,6 +818,13 @@ private: |
|
|
|
void copyWithRounding (Rectangle<int>& result) const noexcept { result = getSmallestIntegerContainer(); }
|
|
|
|
void copyWithRounding (Rectangle<float>& result) const noexcept { result = toFloat(); }
|
|
|
|
void copyWithRounding (Rectangle<double>& result) const noexcept { result = toDouble(); }
|
|
|
|
|
|
|
|
static int floorAsInt (int n) noexcept { return n; }
|
|
|
|
static int floorAsInt (float n) noexcept { return (int) std::floor (n); }
|
|
|
|
static int floorAsInt (double n) noexcept { return (int) std::floor (n); }
|
|
|
|
static int ceilAsInt (int n) noexcept { return n; }
|
|
|
|
static int ceilAsInt (float n) noexcept { return (int) std::ceil (n); }
|
|
|
|
static int ceilAsInt (double n) noexcept { return (int) std::ceil (n); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|