mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibGfx: Add Rect::interpolated_to function
This function interpolates the edges between the rectangle and another rectangle based on a percentage value.
This commit is contained in:
parent
9ff1fa1cf3
commit
035b0f9df6
Notes:
sideshowbarker
2024-07-16 23:23:26 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/035b0f9df6 Pull-request: https://github.com/SerenityOS/serenity/pull/18175 Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/nico ✅ Reviewed-by: https://github.com/trflynn89
1 changed files with 18 additions and 0 deletions
|
@ -557,6 +557,24 @@ public:
|
|||
return points;
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
[[nodiscard]] Gfx::Rect<U> interpolated_to(Gfx::Rect<T> 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<U>(mix<float>(x(), to.x(), factor));
|
||||
auto interpolated_top = round_to<U>(mix<float>(y(), to.y(), factor));
|
||||
auto interpolated_right = round_to<U>(mix<float>(right(), to.right(), factor));
|
||||
auto interpolated_bottom = round_to<U>(mix<float>(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<T> const& other) const
|
||||
{
|
||||
return Line { center(), other.center() }.length();
|
||||
|
|
Loading…
Reference in a new issue