Loading include/ui/TVecHelpers.h +98 −14 Original line number Diff line number Diff line Loading @@ -321,6 +321,66 @@ public: constexpr bool PURE operator >=(const VECTOR<T>& lv, const VECTOR<RT>& rv) { return !(lv < rv); } template<typename RT> friend inline constexpr VECTOR<bool> PURE equal(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] == rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE notEqual(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] != rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE lessThan(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] < rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE lessThanEqual(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] <= rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE greaterThan(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] > rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE greaterThanEqual(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] >= rv[i]; } return r; } }; /* Loading Loading @@ -488,6 +548,30 @@ public: } return v; } friend inline CONSTEXPR bool PURE any(const VECTOR<T>& v) { for (size_t i = 0; i < v.size(); i++) { if (v[i] != T(0)) return true; } return false; } friend inline CONSTEXPR bool PURE all(const VECTOR<T>& v) { bool result = true; for (size_t i = 0; i < v.size(); i++) { result &= (v[i] != T(0)); } return result; } template<typename R> friend inline CONSTEXPR VECTOR<R> PURE map(VECTOR<T> v, const std::function<R(T)>& f) { VECTOR<R> result; for (size_t i = 0; i < v.size(); i++) { result[i] = f(v[i]); } return result; } }; /* Loading include/ui/vec2.h +1 −0 Original line number Diff line number Diff line Loading @@ -118,6 +118,7 @@ typedef details::TVec2<int16_t> short2; typedef details::TVec2<uint16_t> ushort2; typedef details::TVec2<int8_t> byte2; typedef details::TVec2<uint8_t> ubyte2; typedef details::TVec2<bool> bool2; // ---------------------------------------------------------------------------------------- } // namespace android Loading include/ui/vec3.h +1 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ typedef details::TVec3<int16_t> short3; typedef details::TVec3<uint16_t> ushort3; typedef details::TVec3<int8_t> byte3; typedef details::TVec3<uint8_t> ubyte3; typedef details::TVec3<bool> bool3; // ---------------------------------------------------------------------------------------- } // namespace android Loading include/ui/vec4.h +1 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,7 @@ typedef details::TVec4<int16_t> short4; typedef details::TVec4<uint16_t> ushort4; typedef details::TVec4<int8_t> byte4; typedef details::TVec4<uint8_t> ubyte4; typedef details::TVec4<bool> bool4; // ---------------------------------------------------------------------------------------- } // namespace android Loading libs/ui/tests/vec_test.cpp +32 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,23 @@ TEST_F(VecTest, ComparisonOps) { EXPECT_FALSE(v0 == v1); } TEST_F(VecTest, ComparisonFunctions) { vec4 v0(1, 2, 3, 4); vec4 v1(10, 20, 30, 40); EXPECT_TRUE(all(equal(v0, v0))); EXPECT_TRUE(all(notEqual(v0, v1))); EXPECT_FALSE(any(notEqual(v0, v0))); EXPECT_FALSE(any(equal(v0, v1))); EXPECT_FALSE(all(lessThan(v0, v0))); EXPECT_TRUE(all(lessThanEqual(v0, v0))); EXPECT_FALSE(all(greaterThan(v0, v0))); EXPECT_TRUE(all(greaterThanEqual(v0, v0))); EXPECT_TRUE(all(lessThan(v0, v1))); EXPECT_TRUE(all(greaterThan(v1, v0))); } TEST_F(VecTest, ArithmeticOps) { vec4 v0(1, 2, 3, 4); vec4 v1(10, 20, 30, 40); Loading Loading @@ -233,6 +250,21 @@ TEST_F(VecTest, ArithmeticFunc) { float3 vf(east); EXPECT_EQ(length(vf), 1); EXPECT_TRUE(any(vec3(0, 0, 1))); EXPECT_FALSE(any(vec3(0, 0, 0))); EXPECT_TRUE(all(vec3(1, 1, 1))); EXPECT_FALSE(all(vec3(0, 0, 1))); EXPECT_TRUE(any(bool3(false, false, true))); EXPECT_FALSE(any(bool3(false))); EXPECT_TRUE(all(bool3(true))); EXPECT_FALSE(all(bool3(false, false, true))); std::function<bool(float)> p = [](auto v) -> bool { return v > 0.0f; }; EXPECT_TRUE(all(map(vec3(1, 2, 3), p))); } }; // namespace android Loading
include/ui/TVecHelpers.h +98 −14 Original line number Diff line number Diff line Loading @@ -321,6 +321,66 @@ public: constexpr bool PURE operator >=(const VECTOR<T>& lv, const VECTOR<RT>& rv) { return !(lv < rv); } template<typename RT> friend inline constexpr VECTOR<bool> PURE equal(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] == rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE notEqual(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] != rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE lessThan(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] < rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE lessThanEqual(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] <= rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE greaterThan(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] > rv[i]; } return r; } template<typename RT> friend inline constexpr VECTOR<bool> PURE greaterThanEqual(const VECTOR<T>& lv, const VECTOR<RT>& rv) { VECTOR<bool> r; for (size_t i = 0; i < lv.size(); i++) { r[i] = lv[i] >= rv[i]; } return r; } }; /* Loading Loading @@ -488,6 +548,30 @@ public: } return v; } friend inline CONSTEXPR bool PURE any(const VECTOR<T>& v) { for (size_t i = 0; i < v.size(); i++) { if (v[i] != T(0)) return true; } return false; } friend inline CONSTEXPR bool PURE all(const VECTOR<T>& v) { bool result = true; for (size_t i = 0; i < v.size(); i++) { result &= (v[i] != T(0)); } return result; } template<typename R> friend inline CONSTEXPR VECTOR<R> PURE map(VECTOR<T> v, const std::function<R(T)>& f) { VECTOR<R> result; for (size_t i = 0; i < v.size(); i++) { result[i] = f(v[i]); } return result; } }; /* Loading
include/ui/vec2.h +1 −0 Original line number Diff line number Diff line Loading @@ -118,6 +118,7 @@ typedef details::TVec2<int16_t> short2; typedef details::TVec2<uint16_t> ushort2; typedef details::TVec2<int8_t> byte2; typedef details::TVec2<uint8_t> ubyte2; typedef details::TVec2<bool> bool2; // ---------------------------------------------------------------------------------------- } // namespace android Loading
include/ui/vec3.h +1 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ typedef details::TVec3<int16_t> short3; typedef details::TVec3<uint16_t> ushort3; typedef details::TVec3<int8_t> byte3; typedef details::TVec3<uint8_t> ubyte3; typedef details::TVec3<bool> bool3; // ---------------------------------------------------------------------------------------- } // namespace android Loading
include/ui/vec4.h +1 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,7 @@ typedef details::TVec4<int16_t> short4; typedef details::TVec4<uint16_t> ushort4; typedef details::TVec4<int8_t> byte4; typedef details::TVec4<uint8_t> ubyte4; typedef details::TVec4<bool> bool4; // ---------------------------------------------------------------------------------------- } // namespace android Loading
libs/ui/tests/vec_test.cpp +32 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,23 @@ TEST_F(VecTest, ComparisonOps) { EXPECT_FALSE(v0 == v1); } TEST_F(VecTest, ComparisonFunctions) { vec4 v0(1, 2, 3, 4); vec4 v1(10, 20, 30, 40); EXPECT_TRUE(all(equal(v0, v0))); EXPECT_TRUE(all(notEqual(v0, v1))); EXPECT_FALSE(any(notEqual(v0, v0))); EXPECT_FALSE(any(equal(v0, v1))); EXPECT_FALSE(all(lessThan(v0, v0))); EXPECT_TRUE(all(lessThanEqual(v0, v0))); EXPECT_FALSE(all(greaterThan(v0, v0))); EXPECT_TRUE(all(greaterThanEqual(v0, v0))); EXPECT_TRUE(all(lessThan(v0, v1))); EXPECT_TRUE(all(greaterThan(v1, v0))); } TEST_F(VecTest, ArithmeticOps) { vec4 v0(1, 2, 3, 4); vec4 v1(10, 20, 30, 40); Loading Loading @@ -233,6 +250,21 @@ TEST_F(VecTest, ArithmeticFunc) { float3 vf(east); EXPECT_EQ(length(vf), 1); EXPECT_TRUE(any(vec3(0, 0, 1))); EXPECT_FALSE(any(vec3(0, 0, 0))); EXPECT_TRUE(all(vec3(1, 1, 1))); EXPECT_FALSE(all(vec3(0, 0, 1))); EXPECT_TRUE(any(bool3(false, false, true))); EXPECT_FALSE(any(bool3(false))); EXPECT_TRUE(all(bool3(true))); EXPECT_FALSE(all(bool3(false, false, true))); std::function<bool(float)> p = [](auto v) -> bool { return v > 0.0f; }; EXPECT_TRUE(all(map(vec3(1, 2, 3), p))); } }; // namespace android