| 58 | |
| 59 | |
| 60 | struct ColorHSV { |
| 61 | ColorHSV() : h_(0), s_(0), v_(0) {} |
| 62 | ColorHSV(float h, float s, float v) { |
| 63 | Set(h,s,v); |
| 64 | } |
| 65 | explicit ColorHSV(const Color3i& color) { |
| 66 | FromRGB(color); |
| 67 | } |
| 68 | ColorHSV& operator=(const Color3i& color) { |
| 69 | FromRGB(color); |
| 70 | return *this; |
| 71 | } |
| 72 | ColorHSV(const ColorHSV& other) { |
| 73 | Set(other); |
| 74 | } |
| 75 | ColorHSV& operator=(const ColorHSV& other) { |
| 76 | if (this != &other) { |
| 77 | Set(other); |
| 78 | } |
| 79 | return *this; |
| 80 | } |
| 81 | void Set(const ColorHSV& other) { |
| 82 | Set(other.h_, other.s_, other.v_); |
| 83 | } |
| 84 | void Set(float h, float s, float v) { |
| 85 | h_ = h; |
| 86 | s_ = s; |
| 87 | v_ = v; |
| 88 | } |
| 89 | |
| 90 | template <typename PrintStream> |
| 91 | inline void Print(PrintStream* stream) { |
| 92 | stream->print("HSV:\t"); |
| 93 | stream->print(h_); stream->print(",\t"); |
| 94 | stream->print(s_); stream->print(",\t"); |
| 95 | stream->print(v_); stream->print("\n"); |
| 96 | } |
| 97 | |
| 98 | bool operator==(const ColorHSV& other) const { |
| 99 | return h_ == other.h_ && s_ == other.s_ && v_ == other.v_; |
| 100 | } |
| 101 | bool operator!=(const ColorHSV& other) const { |
| 102 | return !(*this == other); |
| 103 | } |
| 104 | void FromRGB(const Color3i& rgb); |
| 105 | |
| 106 | Color3i ToRGB() const; |
| 107 | |
| 108 | float h_, s_, v_; |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | #endif // COLOR_H_ |