diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index cd2ac0b947..9d54efa4d3 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -557,6 +557,24 @@ public: return points; } + template + [[nodiscard]] Gfx::Rect interpolated_to(Gfx::Rect const& to, float factor) const + { + VERIFY(factor >= 0.0f); + VERIFY(factor <= 1.0f); + if (factor == 0.0f) + return *this; + if (factor == 1.0f) + return to; + if (this == &to) + return *this; + auto interpolated_left = round_to(mix(x(), to.x(), factor)); + auto interpolated_top = round_to(mix(y(), to.y(), factor)); + auto interpolated_right = round_to(mix(right(), to.right(), factor)); + auto interpolated_bottom = round_to(mix(bottom(), to.bottom(), factor)); + return { interpolated_left, interpolated_top, interpolated_right - interpolated_left + 1, interpolated_bottom - interpolated_top + 1 }; + } + [[nodiscard]] float center_point_distance_to(Rect const& other) const { return Line { center(), other.center() }.length();