just variadic min and max

This commit is contained in:
2019-09-05 02:10:00 +07:00
parent 137ea5c7f6
commit 0e96190872
8 changed files with 122 additions and 29 deletions

View File

@@ -271,11 +271,11 @@ namespace e2d::math
//
f32 minimum(const color& c) noexcept {
return math::min(math::min(math::min(c.r, c.g), c.b), c.a);
return math::min(c.r, c.g, c.b, c.a);
}
f32 maximum(const color& c) noexcept {
return math::max(math::max(math::max(c.r, c.g), c.b), c.a);
return math::max(c.r, c.g, c.b, c.a);
}
//
@@ -322,17 +322,17 @@ namespace e2d::colors
{
u32 pack_color(const color& c) noexcept {
return
math::numeric_cast<u32>(math::round(math::saturate(c.a) * 255.f)) << 24 |
math::numeric_cast<u32>(math::round(math::saturate(c.r) * 255.f)) << 16 |
math::numeric_cast<u32>(math::round(math::saturate(c.g) * 255.f)) << 8 |
math::numeric_cast<u32>(math::round(math::saturate(c.b) * 255.f)) << 0;
static_cast<u32>(math::saturate(c.a) * 255.f + 0.5f) << 24 |
static_cast<u32>(math::saturate(c.r) * 255.f + 0.5f) << 16 |
static_cast<u32>(math::saturate(c.g) * 255.f + 0.5f) << 8 |
static_cast<u32>(math::saturate(c.b) * 255.f + 0.5f) << 0;
}
color unpack_color(u32 argb) noexcept {
return color(
math::numeric_cast<u8>((argb >> 16) & 0xFF) / 255.f,
math::numeric_cast<u8>((argb >> 8) & 0xFF) / 255.f,
math::numeric_cast<u8>((argb >> 0) & 0xFF) / 255.f,
math::numeric_cast<u8>((argb >> 24) & 0xFF) / 255.f);
static_cast<u8>((argb >> 16) & 0xFF) / 255.f,
static_cast<u8>((argb >> 8) & 0xFF) / 255.f,
static_cast<u8>((argb >> 0) & 0xFF) / 255.f,
static_cast<u8>((argb >> 24) & 0xFF) / 255.f);
}
}

View File

@@ -55,10 +55,10 @@ namespace e2d
}
color32::color32(const color& other) noexcept
: r(u8(other.r * 255.0f + 0.5f))
, g(u8(other.g * 255.0f + 0.5f))
, b(u8(other.b * 255.0f + 0.5f))
, a(u8(other.a * 255.0f + 0.5f)) {}
: r(static_cast<u8>(math::saturate(other.r) * 255.f + 0.5f))
, g(static_cast<u8>(math::saturate(other.g) * 255.f + 0.5f))
, b(static_cast<u8>(math::saturate(other.b) * 255.f + 0.5f))
, a(static_cast<u8>(math::saturate(other.a) * 255.f + 0.5f)) {}
color32::color32(u8 nr, u8 ng, u8 nb, u8 na) noexcept
: r(nr)
@@ -271,11 +271,11 @@ namespace e2d::math
//
u8 minimum(const color32& c) noexcept {
return math::min(math::min(math::min(c.r, c.g), c.b), c.a);
return math::min(c.r, c.g, c.b, c.a);
}
u8 maximum(const color32& c) noexcept {
return math::max(math::max(math::max(c.r, c.g), c.b), c.a);
return math::max(c.r, c.g, c.b, c.a);
}
//
@@ -322,17 +322,17 @@ namespace e2d::colors
{
u32 pack_color32(const color32& c) noexcept {
return
math::numeric_cast<u32>(c.a) << 24 |
math::numeric_cast<u32>(c.r) << 16 |
math::numeric_cast<u32>(c.g) << 8 |
math::numeric_cast<u32>(c.b) << 0;
static_cast<u32>(c.a) << 24 |
static_cast<u32>(c.r) << 16 |
static_cast<u32>(c.g) << 8 |
static_cast<u32>(c.b) << 0;
}
color32 unpack_color32(u32 argb) noexcept {
return color32(
math::numeric_cast<u8>((argb >> 16) & 0xFF),
math::numeric_cast<u8>((argb >> 8) & 0xFF),
math::numeric_cast<u8>((argb >> 0) & 0xFF),
math::numeric_cast<u8>((argb >> 24) & 0xFF));
static_cast<u8>((argb >> 16) & 0xFF),
static_cast<u8>((argb >> 8) & 0xFF),
static_cast<u8>((argb >> 0) & 0xFF),
static_cast<u8>((argb >> 24) & 0xFF));
}
}