From c27a12bb3089022728d153bf6695b66691bfc160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 14 Dec 2016 16:08:07 +0100 Subject: [PATCH] Math: renamed Color[34]::*HSV types and functions to Color[34]::*Hsv. For consistency with naming scheme for other color spaces (upcoming Srgb, Xyz, Lab etc.). The old uppercase names are now marked as deprecated and will be removed in some future release. --- src/Magnum/Math/Color.h | 120 +++++++++++++++++++++-------- src/Magnum/Math/Test/ColorTest.cpp | 54 ++++++------- 2 files changed, 117 insertions(+), 57 deletions(-) diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index 3a48a3b73..bbd898d70 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -39,7 +39,7 @@ namespace Magnum { namespace Math { namespace Implementation { /* Convert color from HSV */ -template typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { +template typename std::enable_if::value, Color3>::type fromHsv(typename Color3::Hsv hsv) { Deg hue; T saturation, value; std::tie(hue, saturation, value) = hsv; @@ -65,8 +65,8 @@ template typename std::enable_if::value, Colo default: CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ } } -template inline typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { - return denormalize>(fromHSV::FloatingPointType>(hsv)); +template inline typename std::enable_if::value, Color3>::type fromHsv(typename Color3::Hsv hsv) { + return denormalize>(fromHsv::FloatingPointType>(hsv)); } /* Internal hue computing function */ @@ -113,14 +113,14 @@ template inline typename Color3::FloatingPointType value(typename st } /* Convert color to HSV */ -template inline typename Color3::HSV toHSV(typename std::enable_if::value, const Color3&>::type color) { +template inline typename Color3::Hsv toHsv(typename std::enable_if::value, const Color3&>::type color) { T max = color.max(); T delta = max - color.min(); - return typename Color3::HSV(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); + return typename Color3::Hsv(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); } -template inline typename Color3::HSV toHSV(typename std::enable_if::value, const Color3&>::type color) { - return toHSV::FloatingPointType>(normalize::FloatingPointType>>(color)); +template inline typename Color3::Hsv toHsv(typename std::enable_if::value, const Color3&>::type color) { + return toHsv::FloatingPointType>(normalize::FloatingPointType>>(color)); } /* Value for full channel (1.0f for floats, 255 for unsigned byte) */ @@ -233,23 +233,46 @@ template class Color3: public Vector3 { * Hue in range @f$ [0.0, 360.0] @f$, saturation and value in * range @f$ [0.0, 1.0] @f$. */ - typedef std::tuple, FloatingPointType, FloatingPointType> HSV; + typedef std::tuple, FloatingPointType, FloatingPointType> Hsv; + + #ifdef MAGNUM_BUILD_DEPRECATED + /** @copybrief Hsv + * @deprecated Use @ref Hsv instead. + */ + typedef CORRADE_DEPRECATED("use Hsv instead") Hsv HSV; + #endif /** * @brief Create RGB color from HSV representation * @param hsv Hue, saturation and value * * Hue can overflow the range @f$ [0.0, 360.0] @f$. - * @see @ref toHSV() + * @see @ref toHsv() */ - static Color3 fromHSV(HSV hsv) { - return Implementation::fromHSV(hsv); + static Color3 fromHsv(Hsv hsv) { + return Implementation::fromHsv(hsv); } /** @overload */ - static Color3 fromHSV(Deg hue, FloatingPointType saturation, FloatingPointType value) { - return fromHSV(std::make_tuple(hue, saturation, value)); + static Color3 fromHsv(Deg hue, FloatingPointType saturation, FloatingPointType value) { + return fromHsv(std::make_tuple(hue, saturation, value)); } + #ifdef MAGNUM_BUILD_DEPRECATED + /** @copybrief fromHsv(Hsv) + * @deprecated Use @ref fromHsv(Hsv) instead. + */ + CORRADE_DEPRECATED("use fromHsv() instead") static Color3 fromHSV(Hsv hsv) { + return fromHsv(hsv); + } + /** @copybrief fromHsv(Deg, FloatingPointType, FloatingPointType) + * @deprecated Use @ref fromHsv(Deg, FloatingPointType, FloatingPointType) + * instead. + */ + CORRADE_DEPRECATED("use fromHsv() instead") static Color3 fromHSV(Deg hue, FloatingPointType saturation, FloatingPointType value) { + return fromHsv(hue, saturation, value); + } + #endif + /** * @brief Default constructor * @@ -315,20 +338,27 @@ template class Color3: public Vector3 { * @code * Deg hue; * Float saturation, value; - * std::tie(hue, saturation, value) = color.toHSV(); + * std::tie(hue, saturation, value) = color.toHsv(); * @endcode * - * @see @ref hue(), @ref saturation(), @ref value(), @ref fromHSV() + * @see @ref hue(), @ref saturation(), @ref value(), @ref fromHSv() */ - HSV toHSV() const { - return Implementation::toHSV(*this); + Hsv toHsv() const { + return Implementation::toHsv(*this); } + #ifdef MAGNUM_BUILD_DEPRECATED + /** @copybrief toHsv() + * @deprecated Use @ref toHsv() instead. + */ + CORRADE_DEPRECATED("use toHsv() instead") Hsv toHSV() const { return toHsv(); } + #endif + /** * @brief Hue * @return Hue in range @f$ [0.0, 360.0] @f$. * - * @see @ref saturation(), @ref value(), @ref toHSV(), @ref fromHSV() + * @see @ref saturation(), @ref value(), @ref toHsv(), @ref fromHsv() */ Deg hue() const { return Deg(Implementation::hue(*this)); @@ -338,7 +368,7 @@ template class Color3: public Vector3 { * @brief Saturation * @return Saturation in range @f$ [0.0, 1.0] @f$. * - * @see @ref hue(), @ref value(), @ref toHSV(), @ref fromHSV() + * @see @ref hue(), @ref value(), @ref toHsv(), @ref fromHsv() */ FloatingPointType saturation() const { return Implementation::saturation(*this); @@ -348,7 +378,7 @@ template class Color3: public Vector3 { * @brief Value * @return Value in range @f$ [0.0, 1.0] @f$. * - * @see @ref hue(), @ref saturation(), @ref toHSV(), @ref fromHSV() + * @see @ref hue(), @ref saturation(), @ref toHsv(), @ref fromHsv() */ FloatingPointType value() const { return Implementation::value(*this); @@ -380,8 +410,15 @@ class Color4: public Vector4 { /** @copydoc Color3::FloatingPointType */ typedef typename Color3::FloatingPointType FloatingPointType; - /** @copydoc Color3::HSV */ - typedef typename Color3::HSV HSV; + /** @copydoc Color3::Hsv */ + typedef typename Color3::Hsv Hsv; + + #ifdef MAGNUM_BUILD_DEPRECATED + /** @copybrief Hsv + * @deprecated Use @ref Hsv instead. + */ + typedef CORRADE_DEPRECATED("use Hsv instead") Hsv HSV; + #endif /** * @brief Red color @@ -450,16 +487,32 @@ class Color4: public Vector4 { * and maximum positive value for integral types. * * Hue can overflow the range @f$ [0.0, 360.0] @f$. - * @see @ref toHSV() + * @see @ref toHsv() */ - static Color4 fromHSV(HSV hsv, T a = Implementation::fullChannel()) { - return Color4(Implementation::fromHSV(hsv), a); + static Color4 fromHsv(Hsv hsv, T a = Implementation::fullChannel()) { + return Color4(Implementation::fromHsv(hsv), a); } /** @overload */ - static Color4 fromHSV(Deg hue, FloatingPointType saturation, FloatingPointType value, T alpha = Implementation::fullChannel()) { - return fromHSV(std::make_tuple(hue, saturation, value), alpha); + static Color4 fromHsv(Deg hue, FloatingPointType saturation, FloatingPointType value, T alpha = Implementation::fullChannel()) { + return fromHsv(std::make_tuple(hue, saturation, value), alpha); } + #ifdef MAGNUM_BUILD_DEPRECATED + /** @copybrief fromHsv(Hsv, T) + * @deprecated Use @ref fromHsv(Hsv, T) instead. + */ + CORRADE_DEPRECATED("use fromHsv() instead") static Color4 fromHSV(Hsv hsv, T a = Implementation::fullChannel()) { + return fromHsv(hsv, a); + } + /** @copybrief fromHsv(Deg, FloatingPointType, FloatingPointType, T) + * @deprecated Use @ref fromHsv(Deg, FloatingPointType, FloatingPointType, T) + * instead. + */ + CORRADE_DEPRECATED("use fromHsv() instead") static Color4 fromHSV(Deg hue, FloatingPointType saturation, FloatingPointType value, T a = Implementation::fullChannel()) { + return fromHsv(hue, saturation, value, a); + } + #endif + /** * @brief Default constructor * @@ -533,11 +586,18 @@ class Color4: public Vector4 { /** @brief Copy constructor */ constexpr /*implicit*/ Color4(const Vector<4, T>& other) noexcept: Vector4(other) {} - /** @copydoc Color3::toHSV() */ - HSV toHSV() const { - return Implementation::toHSV(Vector4::rgb()); + /** @copydoc Color3::toHsv() */ + Hsv toHsv() const { + return Implementation::toHsv(Vector4::rgb()); } + #ifdef MAGNUM_BUILD_DEPRECATED + /** @copybrief toHsv() + * @deprecated Use @ref toHsv() instead. + */ + CORRADE_DEPRECATED("use toHsv() instead") Hsv toHSV() const { return toHsv(); } + #endif + /** @copydoc Color3::hue() */ Deg hue() const { return Implementation::hue(Vector4::rgb()); diff --git a/src/Magnum/Math/Test/ColorTest.cpp b/src/Magnum/Math/Test/ColorTest.cpp index cd9b2d920..b5d27db29 100644 --- a/src/Magnum/Math/Test/ColorTest.cpp +++ b/src/Magnum/Math/Test/ColorTest.cpp @@ -371,12 +371,12 @@ void ColorTest::colors() { } void ColorTest::fromHue() { - CORRADE_COMPARE(Color3ub::fromHSV(27.0_degf, 1.0f, 1.0f), Color3ub(255, 114, 0)); - CORRADE_COMPARE(Color3ub::fromHSV(86.0_degf, 1.0f, 1.0f), Color3ub(144, 255, 0)); - CORRADE_COMPARE(Color3ub::fromHSV(134.0_degf, 1.0f, 1.0f), Color3ub(0, 255, 59)); - CORRADE_COMPARE(Color3ub::fromHSV(191.0_degf, 1.0f, 1.0f), Color3ub(0, 208, 255)); - CORRADE_COMPARE(Color3ub::fromHSV(269.0_degf, 1.0f, 1.0f), Color3ub(123, 0, 255)); - CORRADE_COMPARE(Color3ub::fromHSV(317.0_degf, 1.0f, 1.0f), Color3ub(255, 0, 182)); + CORRADE_COMPARE(Color3ub::fromHsv(27.0_degf, 1.0f, 1.0f), Color3ub(255, 114, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(86.0_degf, 1.0f, 1.0f), Color3ub(144, 255, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(134.0_degf, 1.0f, 1.0f), Color3ub(0, 255, 59)); + CORRADE_COMPARE(Color3ub::fromHsv(191.0_degf, 1.0f, 1.0f), Color3ub(0, 208, 255)); + CORRADE_COMPARE(Color3ub::fromHsv(269.0_degf, 1.0f, 1.0f), Color3ub(123, 0, 255)); + CORRADE_COMPARE(Color3ub::fromHsv(317.0_degf, 1.0f, 1.0f), Color3ub(255, 0, 182)); } void ColorTest::hue() { @@ -389,7 +389,7 @@ void ColorTest::hue() { } void ColorTest::fromSaturation() { - CORRADE_COMPARE(Color3ub::fromHSV(0.0_degf, 0.702f, 1.0f), Color3ub(255, 75, 75)); + CORRADE_COMPARE(Color3ub::fromHsv(0.0_degf, 0.702f, 1.0f), Color3ub(255, 75, 75)); } void ColorTest::saturation() { @@ -398,7 +398,7 @@ void ColorTest::saturation() { } void ColorTest::fromValue() { - CORRADE_COMPARE(Color3ub::fromHSV(0.0_degf, 1.0f, 0.522f), Color3ub(133, 0, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(0.0_degf, 1.0f, 0.522f), Color3ub(133, 0, 0)); } void ColorTest::value() { @@ -406,39 +406,39 @@ void ColorTest::value() { } void ColorTest::hsv() { - CORRADE_COMPARE(Color3ub::fromHSV(230.0_degf, 0.749f, 0.427f), Color3ub(27, 40, 108)); + CORRADE_COMPARE(Color3ub::fromHsv(230.0_degf, 0.749f, 0.427f), Color3ub(27, 40, 108)); Deg hue; Float saturation, value; - std::tie(hue, saturation, value) = Color3ub(27, 41, 109).toHSV(); + std::tie(hue, saturation, value) = Color3ub(27, 41, 109).toHsv(); CORRADE_COMPARE(hue, 229.756106_degf); CORRADE_COMPARE(saturation, 0.752294f); CORRADE_COMPARE(value, 0.427451f); } void ColorTest::hsvOverflow() { - CORRADE_COMPARE(Color3ub::fromHSV(27.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(255, 114, 0)); - CORRADE_COMPARE(Color3ub::fromHSV(86.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(144, 255, 0)); - CORRADE_COMPARE(Color3ub::fromHSV(134.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(0, 255, 59)); - CORRADE_COMPARE(Color3ub::fromHSV(191.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(0, 208, 255)); - CORRADE_COMPARE(Color3ub::fromHSV(269.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(123, 0, 255)); - CORRADE_COMPARE(Color3ub::fromHSV(317.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(255, 0, 182)); - - CORRADE_COMPARE(Color3ub::fromHSV(360.0_degf + 27.0_degf, 1.0f, 1.0f), Color3ub(255, 114, 0)); - CORRADE_COMPARE(Color3ub::fromHSV(360.0_degf + 86.0_degf, 1.0f, 1.0f), Color3ub(144, 255, 0)); - CORRADE_COMPARE(Color3ub::fromHSV(360.0_degf + 134.0_degf, 1.0f, 1.0f), Color3ub(0, 255, 59)); - CORRADE_COMPARE(Color3ub::fromHSV(360.0_degf + 191.0_degf, 1.0f, 1.0f), Color3ub(0, 208, 255)); - CORRADE_COMPARE(Color3ub::fromHSV(360.0_degf + 269.0_degf, 1.0f, 1.0f), Color3ub(123, 0, 255)); - CORRADE_COMPARE(Color3ub::fromHSV(360.0_degf + 317.0_degf, 1.0f, 1.0f), Color3ub(255, 0, 182)); + CORRADE_COMPARE(Color3ub::fromHsv(27.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(255, 114, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(86.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(144, 255, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(134.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(0, 255, 59)); + CORRADE_COMPARE(Color3ub::fromHsv(191.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(0, 208, 255)); + CORRADE_COMPARE(Color3ub::fromHsv(269.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(123, 0, 255)); + CORRADE_COMPARE(Color3ub::fromHsv(317.0_degf - 360.0_degf, 1.0f, 1.0f), Color3ub(255, 0, 182)); + + CORRADE_COMPARE(Color3ub::fromHsv(360.0_degf + 27.0_degf, 1.0f, 1.0f), Color3ub(255, 114, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(360.0_degf + 86.0_degf, 1.0f, 1.0f), Color3ub(144, 255, 0)); + CORRADE_COMPARE(Color3ub::fromHsv(360.0_degf + 134.0_degf, 1.0f, 1.0f), Color3ub(0, 255, 59)); + CORRADE_COMPARE(Color3ub::fromHsv(360.0_degf + 191.0_degf, 1.0f, 1.0f), Color3ub(0, 208, 255)); + CORRADE_COMPARE(Color3ub::fromHsv(360.0_degf + 269.0_degf, 1.0f, 1.0f), Color3ub(123, 0, 255)); + CORRADE_COMPARE(Color3ub::fromHsv(360.0_degf + 317.0_degf, 1.0f, 1.0f), Color3ub(255, 0, 182)); } void ColorTest::hsvAlpha() { - CORRADE_COMPARE(Color4ub::fromHSV(std::make_tuple(230.0_degf, 0.749f, 0.427f), 23), Color4ub(27, 40, 108, 23)); - CORRADE_COMPARE(Color4ub::fromHSV(230.0_degf, 0.749f, 0.427f, 23), Color4ub(27, 40, 108, 23)); + CORRADE_COMPARE(Color4ub::fromHsv(std::make_tuple(230.0_degf, 0.749f, 0.427f), 23), Color4ub(27, 40, 108, 23)); + CORRADE_COMPARE(Color4ub::fromHsv(230.0_degf, 0.749f, 0.427f, 23), Color4ub(27, 40, 108, 23)); /* Default alpha */ - CORRADE_COMPARE(Color4ub::fromHSV(std::make_tuple(230.0_degf, 0.749f, 0.427f)), Color4ub(27, 40, 108, 255)); - CORRADE_COMPARE(Color4ub::fromHSV(230.0_degf, 0.749f, 0.427f), Color4ub(27, 40, 108, 255)); + CORRADE_COMPARE(Color4ub::fromHsv(std::make_tuple(230.0_degf, 0.749f, 0.427f)), Color4ub(27, 40, 108, 255)); + CORRADE_COMPARE(Color4ub::fromHsv(230.0_degf, 0.749f, 0.427f), Color4ub(27, 40, 108, 255)); } void ColorTest::swizzleType() {