make_vecX from color and color32

This commit is contained in:
2019-08-17 10:59:34 +07:00
parent 467da73019
commit 2eecc0ae6e
6 changed files with 30 additions and 0 deletions

View File

@@ -55,6 +55,9 @@ namespace e2d
namespace e2d
{
vec3<f32> make_vec3(const color& c) noexcept;
vec4<f32> make_vec4(const color& c) noexcept;
bool operator<(const color& l, const color& r) noexcept;
bool operator==(const color& l, const color& r) noexcept;
bool operator!=(const color& l, const color& r) noexcept;

View File

@@ -55,6 +55,9 @@ namespace e2d
namespace e2d
{
vec3<u8> make_vec3(const color32& c) noexcept;
vec4<u8> make_vec4(const color32& c) noexcept;
bool operator<(const color32& l, const color32& r) noexcept;
bool operator==(const color32& l, const color32& r) noexcept;
bool operator!=(const color32& l, const color32& r) noexcept;

View File

@@ -139,6 +139,14 @@ namespace e2d
namespace e2d
{
vec3<f32> make_vec3(const color& c) noexcept {
return make_vec3(c.r, c.g, c.b);
}
vec4<f32> make_vec4(const color& c) noexcept {
return make_vec4(c.r, c.g, c.b, c.a);
}
//
// color (<,==,!=) color
//

View File

@@ -139,6 +139,14 @@ namespace e2d
namespace e2d
{
vec3<u8> make_vec3(const color32& c) noexcept {
return make_vec3(c.r, c.g, c.b);
}
vec4<u8> make_vec4(const color32& c) noexcept {
return make_vec4(c.r, c.g, c.b, c.a);
}
//
// color32 (<,==,!=) color32
//

View File

@@ -48,6 +48,10 @@ TEST_CASE("color") {
c /= color(0.1f,0.2f,0.3f,0.4f);
REQUIRE(c == color(0.5f,0.6f,0.7f,0.8f));
}
{
REQUIRE(make_vec3(color(0.1f,0.2f,0.3f,0.4f)) == v3f(0.1f,0.2f,0.3f));
REQUIRE(make_vec4(color(0.1f,0.2f,0.3f,0.4f)) == v4f(0.1f,0.2f,0.3f, 0.4f));
}
{
REQUIRE(color(0.1f,0.2f,0.3f,0.4f) + 0.1f == color(0.2f,0.3f,0.4f,0.5f));
REQUIRE(color(0.1f,0.2f,0.3f,0.4f) - 0.1f == color(0.0f,0.1f,0.2f,0.3f));

View File

@@ -50,6 +50,10 @@ TEST_CASE("color32") {
c /= color32(2,3,6,7);
REQUIRE(c == color32(40,50,40,20));
}
{
REQUIRE(make_vec3(color32(10,20,30,40)) == vec3<u8>(10,20,30));
REQUIRE(make_vec4(color32(10,20,30,40)) == vec4<u8>(10,20,30,40));
}
{
REQUIRE(color32(10,20,30,40) + 10 == color32(20,30,40,50));
REQUIRE(color32(10,20,30,40) - 10 == color32(0,10,20,30));