From 0d8a15bfb4cc285602189016041228e9b349a52e Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 8 Dec 2010 11:48:56 -0300 Subject: [PATCH] Fix hsv_unittests using floor() in hueInt/saturationInt/valueInt. --- src/gfx/hsv.cpp | 15 +++++++++++++++ src/gfx/hsv.h | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/gfx/hsv.cpp b/src/gfx/hsv.cpp index f107228a9..dc4ae6947 100644 --- a/src/gfx/hsv.cpp +++ b/src/gfx/hsv.cpp @@ -69,3 +69,18 @@ Hsv::Hsv(const Rgb& rgb) m_saturation = s; m_value = v; } + +int Hsv::hueInt() const +{ + return int(floor(m_hue + 0.5)); +} + +int Hsv::saturationInt() const +{ + return int(floor(m_hue*100.0 + 0.5)); +} + +int Hsv::valueInt() const +{ + return int(floor(m_value*100.0 + 0.5)); +} diff --git a/src/gfx/hsv.h b/src/gfx/hsv.h index 4d80c3baf..c119754f3 100644 --- a/src/gfx/hsv.h +++ b/src/gfx/hsv.h @@ -33,22 +33,25 @@ public: // RGB to HSV conversion explicit Hsv(const Rgb& rgb); + // Returns color's hue, a value from 0 to 360 double hue() const { return m_hue; } + // Returns color's saturation, a value from 0 to 100 double saturation() const { return m_saturation; } + // Returns color's brightness, a value from 0 to 100 double value() const { return m_value; } - // Getters in "int" type, hue=[0,360), saturation=[0,100], value=[0,100] - int hueInt() const { return int(m_hue+0.5); } - int saturationInt() const { return int(m_saturation*100.0+0.5); } - int valueInt() const { return int(m_value*100.0+0.5); } + // Integer getters, hue=[0,360), saturation=[0,100], value=[0,100] + int hueInt() const; + int saturationInt() const; + int valueInt() const; void hue(double hue) { assert(hue >= 0.0 && hue <= 360.0); @@ -65,11 +68,11 @@ public: m_value = value; } + // The comparison is done through the integer value of each component. bool operator==(const Hsv& other) const { - // Compare floating points as integers (saturation and value are compared in [0,255] range) - return (int(m_hue+0.5) == int(other.m_hue+0.5) && - int(m_saturation*255.0+0.5) == int(other.m_saturation*255.0+0.5) && - int(m_value*255.0+0.5) == int(other.m_value*255.0+0.5)); + return (hueInt() == other.hueInt() && + saturationInt() == other.saturationInt() && + valueInt() == other.valueInt()); } bool operator!=(const Hsv& other) const {