mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-05 21:57:20 +00:00
Fix hsv_unittests using floor() in hueInt/saturationInt/valueInt.
This commit is contained in:
parent
d4caa65cae
commit
0d8a15bfb4
@ -69,3 +69,18 @@ Hsv::Hsv(const Rgb& rgb)
|
|||||||
m_saturation = s;
|
m_saturation = s;
|
||||||
m_value = v;
|
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));
|
||||||
|
}
|
||||||
|
@ -33,22 +33,25 @@ public:
|
|||||||
// RGB to HSV conversion
|
// RGB to HSV conversion
|
||||||
explicit Hsv(const Rgb& rgb);
|
explicit Hsv(const Rgb& rgb);
|
||||||
|
|
||||||
|
// Returns color's hue, a value from 0 to 360
|
||||||
double hue() const {
|
double hue() const {
|
||||||
return m_hue;
|
return m_hue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns color's saturation, a value from 0 to 100
|
||||||
double saturation() const {
|
double saturation() const {
|
||||||
return m_saturation;
|
return m_saturation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns color's brightness, a value from 0 to 100
|
||||||
double value() const {
|
double value() const {
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters in "int" type, hue=[0,360), saturation=[0,100], value=[0,100]
|
// Integer getters, hue=[0,360), saturation=[0,100], value=[0,100]
|
||||||
int hueInt() const { return int(m_hue+0.5); }
|
int hueInt() const;
|
||||||
int saturationInt() const { return int(m_saturation*100.0+0.5); }
|
int saturationInt() const;
|
||||||
int valueInt() const { return int(m_value*100.0+0.5); }
|
int valueInt() const;
|
||||||
|
|
||||||
void hue(double hue) {
|
void hue(double hue) {
|
||||||
assert(hue >= 0.0 && hue <= 360.0);
|
assert(hue >= 0.0 && hue <= 360.0);
|
||||||
@ -65,11 +68,11 @@ public:
|
|||||||
m_value = value;
|
m_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The comparison is done through the integer value of each component.
|
||||||
bool operator==(const Hsv& other) const {
|
bool operator==(const Hsv& other) const {
|
||||||
// Compare floating points as integers (saturation and value are compared in [0,255] range)
|
return (hueInt() == other.hueInt() &&
|
||||||
return (int(m_hue+0.5) == int(other.m_hue+0.5) &&
|
saturationInt() == other.saturationInt() &&
|
||||||
int(m_saturation*255.0+0.5) == int(other.m_saturation*255.0+0.5) &&
|
valueInt() == other.valueInt());
|
||||||
int(m_value*255.0+0.5) == int(other.m_value*255.0+0.5));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const Hsv& other) const {
|
bool operator!=(const Hsv& other) const {
|
||||||
|
Loading…
Reference in New Issue
Block a user