fix color api

This commit is contained in:
2019-06-04 17:25:05 +07:00
parent b8bae8bdff
commit 4580ac8476
5 changed files with 33 additions and 30 deletions

View File

@@ -17,17 +17,18 @@ namespace e2d
f32 b = 1.f;
f32 a = 1.f;
public:
static const color& clear() noexcept; /// (0; 0; 0; 0)
static const color& black() noexcept; /// (0; 0; 0; 1)
static const color& white() noexcept; /// (1; 1; 1; 1)
static const color& red() noexcept; /// (1; 0; 0; 1)
static const color& green() noexcept; /// (0; 1; 0; 1)
static const color& blue() noexcept; /// (0; 0; 1; 1)
static const color& yellow() noexcept; /// (1; 1; 0; 1)
static const color& magenta() noexcept; /// (1; 0; 1; 1)
static const color& cyan() noexcept; /// (0; 1; 1; 1)
static const color& clear() noexcept;
static const color& black() noexcept;
static const color& white() noexcept;
static const color& red() noexcept;
static const color& green() noexcept;
static const color& blue() noexcept;
static const color& yellow() noexcept;
static const color& magenta() noexcept;
static const color& cyan() noexcept;
public:
color() noexcept = default;
color(const color& other) noexcept = default;
color& operator=(const color& other) noexcept = default;
@@ -85,7 +86,6 @@ namespace e2d::math
color minimized(const color& c, const color& cmin) noexcept;
color maximized(const color& c, const color& cmax) noexcept;
color clamped(const color& c, const color& cmin, const color& cmax) noexcept;
color saturated(const color& c) noexcept;
bool contains_nan(const color& c) noexcept;
}

View File

@@ -17,17 +17,18 @@ namespace e2d
u8 b = 255;
u8 a = 255;
public:
static const color32& clear() noexcept; /// ( 0; 0; 0; 0 )
static const color32& black() noexcept; /// ( 0; 0; 0; 255)
static const color32& white() noexcept; /// (255; 255; 255; 255)
static const color32& red() noexcept; /// (255; 0; 0; 255)
static const color32& green() noexcept; /// ( 0; 255; 0; 255)
static const color32& blue() noexcept; /// ( 0; 0; 255; 255)
static const color32& yellow() noexcept; /// (255; 255; 0; 255)
static const color32& magenta() noexcept; /// (255; 0; 255; 255)
static const color32& cyan() noexcept; /// ( 0; 255; 255; 255)
static const color32& clear() noexcept;
static const color32& black() noexcept;
static const color32& white() noexcept;
static const color32& red() noexcept;
static const color32& green() noexcept;
static const color32& blue() noexcept;
static const color32& yellow() noexcept;
static const color32& magenta() noexcept;
static const color32& cyan() noexcept;
public:
color32() noexcept = default;
color32(const color32& other) noexcept = default;
color32& operator=(const color32& other) noexcept = default;
@@ -85,6 +86,8 @@ namespace e2d::math
color32 minimized(const color32& c, const color32& cmin) noexcept;
color32 maximized(const color32& c, const color32& cmax) noexcept;
color32 clamped(const color32& c, const color32& cmin, const color32& cmax) noexcept;
bool contains_nan(const color32& c) noexcept;
}
namespace e2d::colors

View File

@@ -298,10 +298,6 @@ namespace e2d::math
math::clamp(c.a, cmin.a, cmax.a));
}
color saturated(const color& c) noexcept {
return clamped(c, color::clear(), color::white());
}
//
// contains_nan
//

View File

@@ -297,6 +297,17 @@ namespace e2d::math
math::clamp(c.b, cmin.b, cmax.b),
math::clamp(c.a, cmin.a, cmax.a));
}
//
// contains_nan
//
bool contains_nan(const color32& c) noexcept {
return !math::is_finite(c.r)
|| !math::is_finite(c.g)
|| !math::is_finite(c.b)
|| !math::is_finite(c.a);
}
}
namespace e2d::colors

View File

@@ -115,13 +115,6 @@ TEST_CASE("color") {
REQUIRE(math::clamped(v0, color(4,5,6,7), color(9,9,9,9)) == color(4,5,6,7));
REQUIRE(math::clamped(v0, color(6,5,4,3), color(9,9,9,9)) == color(6,5,5,6));
REQUIRE(math::clamped(v0, color(7,6,5,4), color(9,9,9,9)) == color(7,6,5,6));
REQUIRE(math::saturated(color(-1,-2,-3,-4)) == color(0,0,0,0));
REQUIRE(math::saturated(color( 2, 3, 4, 5)) == color(1,1,1,1));
REQUIRE(math::saturated(color(-1, 3, 4, 5)) == color(0,1,1,1));
REQUIRE(math::saturated(color(2,0.6f,2,0.7f)) == color(1,0.6f,1,0.7f));
REQUIRE(math::saturated(color(0.6f,-2,2,2)) == color(0.6f,0,1,1));
}
{
{