1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:57:34 +00:00

LibGfx: Fix Clang build failulres in VectorN

Clang didn't accept the friend declaration here, as the class has a
requires clause attached to it, and I couldn't immediately figure
out what it wants instead.

Add accessors for VectorN::m_data and use those where needed instead
for now.
This commit is contained in:
Andreas Kling 2022-05-05 21:44:31 +02:00
parent caf652799f
commit 3a2118cc7d

View file

@ -31,9 +31,6 @@ namespace Gfx {
template<size_t N, typename T> template<size_t N, typename T>
requires(N >= 2 && N <= 4) class VectorN final { requires(N >= 2 && N <= 4) class VectorN final {
template<size_t U, typename V>
friend class VectorN;
static_assert(LOOP_UNROLL_N >= N, "Unroll the entire loop for performance."); static_assert(LOOP_UNROLL_N >= N, "Unroll the entire loop for performance.");
public: public:
@ -71,7 +68,7 @@ public:
{ {
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
m_data[i] += other.m_data[i]; m_data[i] += other.data()[i];
return *this; return *this;
} }
@ -79,7 +76,7 @@ public:
{ {
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
m_data[i] -= other.m_data[i]; m_data[i] -= other.data()[i];
return *this; return *this;
} }
@ -96,7 +93,7 @@ public:
VectorN result; VectorN result;
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
result.m_data[i] = m_data[i] + other.m_data[i]; result.m_data[i] = m_data[i] + other.data()[i];
return result; return result;
} }
@ -105,7 +102,7 @@ public:
VectorN result; VectorN result;
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
result.m_data[i] = m_data[i] - other.m_data[i]; result.m_data[i] = m_data[i] - other.data()[i];
return result; return result;
} }
@ -114,7 +111,7 @@ public:
VectorN result; VectorN result;
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
result.m_data[i] = m_data[i] * other.m_data[i]; result.m_data[i] = m_data[i] * other.data()[i];
return result; return result;
} }
@ -132,7 +129,7 @@ public:
VectorN result; VectorN result;
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
result.m_data[i] = m_data[i] / other.m_data[i]; result.m_data[i] = m_data[i] / other.data()[i];
return result; return result;
} }
@ -161,7 +158,7 @@ public:
T result {}; T result {};
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) for (auto i = 0u; i < N; ++i)
result += m_data[i] * other.m_data[i]; result += m_data[i] * other.data()[i];
return result; return result;
} }
@ -238,13 +235,16 @@ public:
UNROLL_LOOP UNROLL_LOOP
for (auto i = 0u; i < N; ++i) { for (auto i = 0u; i < N; ++i) {
if constexpr (IsSame<T, float>) if constexpr (IsSame<T, float>)
result.m_data[i] = static_cast<U>(lrintf(m_data[i])); result.data()[i] = static_cast<U>(lrintf(m_data[i]));
else else
result.m_data[i] = static_cast<U>(lrint(m_data[i])); result.data()[i] = static_cast<U>(lrint(m_data[i]));
} }
return result; return result;
} }
auto& data() { return m_data; }
auto const& data() const { return m_data; }
private: private:
AK::Array<T, N> m_data; AK::Array<T, N> m_data;
}; };