mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
LibGfx: Reimplement Vector::length()
as a loop
This more generic loop supports arbitrary values of `N` and also gets rid of that strange single argument `AK::hypot` invocation.
This commit is contained in:
parent
d75135663b
commit
62ffe67a9f
Notes:
sideshowbarker
2024-07-17 17:50:14 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/62ffe67a9f Pull-request: https://github.com/SerenityOS/serenity/pull/12911 Reviewed-by: https://github.com/ldm5180
1 changed files with 5 additions and 6 deletions
|
@ -193,12 +193,11 @@ public:
|
|||
|
||||
[[nodiscard]] constexpr T length() const
|
||||
{
|
||||
if constexpr (N == 2)
|
||||
return AK::hypot(m_data[0] * m_data[0] + m_data[1] * m_data[1]);
|
||||
else if constexpr (N == 3)
|
||||
return AK::sqrt(m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]);
|
||||
else
|
||||
return AK::sqrt(m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2] + m_data[3] * m_data[3]);
|
||||
T squared_sum {};
|
||||
UNROLL_LOOP
|
||||
for (auto i = 0u; i < N; ++i)
|
||||
squared_sum += m_data[i] * m_data[i];
|
||||
return AK::sqrt(squared_sum);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr VectorN<2, T> xy() const requires(N >= 3)
|
||||
|
|
Loading…
Reference in a new issue