types.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef COLOR_UTIL_TYPES_H
36 #define COLOR_UTIL_TYPES_H
37 
38 #include <string>
39 
40 namespace color_util
41 {
42 
43 template <typename T>
45 {
46  GenericColorRGBA(T r, T g, T b, T a)
47  : r(r), g(g), b(b), a(a) {}
48 
49  bool operator==(const GenericColorRGBA& other) const
50  {
51  return r == other.r && g == other.g && b == other.b && a == other.a;
52  }
53 
54  T r, g, b, a;
55 
56  std::string toString() const
57  {
58  return "(r: " + std::to_string(r) + ", g: " + std::to_string(b) +
59  ", b: " + std::to_string(g) + ", a: " + std::to_string(a) + ")";
60  }
61 };
62 
63 template <typename T>
65 {
66  GenericColorHSVA(T h, T s, T v, T a)
67  : h(h), s(s), v(v), a(a) {}
68 
69  bool operator==(const GenericColorHSVA& other) const
70  {
71  return h == other.h && s == other.s && v == other.v && a == other.a;
72  }
73 
74  T h, s, v, a;
75 
76  std::string toString() const
77  {
78  return "(h: " + std::to_string(h) + ", s: " + std::to_string(s) +
79  ", v: " + std::to_string(v) + ", a: " + std::to_string(a) + ")";
80  }
81 };
82 
83 struct ColorRGBA : public GenericColorRGBA<double>
84 {
85  explicit ColorRGBA(double r = 0.0, double g = 0.0, double b = 0.0, double a = 1.0)
86  : GenericColorRGBA<double>(r, g, b, a) {}
87 };
88 
89 struct ColorRGBA24 : public GenericColorRGBA<unsigned char>
90 {
91  explicit ColorRGBA24(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0, unsigned char a = 255)
92  : GenericColorRGBA<unsigned char>(r, g, b, a) {}
93 };
94 
95 
96 struct ColorHSVA : public GenericColorHSVA<double>
97 {
98  explicit ColorHSVA(double h = 0.0, double s = 0.0, double v = 0.0, double a = 1.0)
99  : GenericColorHSVA<double>(h, s, v, a) {}
100 };
101 
102 struct ColorHSVA24 : public GenericColorHSVA<unsigned char>
103 {
104  explicit ColorHSVA24(unsigned char h = 0, unsigned char s = 0, unsigned char v = 0, unsigned char a = 255)
105  : GenericColorHSVA<unsigned char>(h, s, v, a) {}
106 };
107 
108 } // namespace color_util
109 
110 #endif // COLOR_UTIL_TYPES_H
std::string toString() const
Definition: types.h:56
std::string toString() const
Definition: types.h:76
bool operator==(const GenericColorRGBA &other) const
Definition: types.h:49
ColorHSVA(double h=0.0, double s=0.0, double v=0.0, double a=1.0)
Definition: types.h:98
ColorRGBA24(unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=255)
Definition: types.h:91
GenericColorHSVA(T h, T s, T v, T a)
Definition: types.h:66
ColorHSVA24(unsigned char h=0, unsigned char s=0, unsigned char v=0, unsigned char a=255)
Definition: types.h:104
ColorRGBA(double r=0.0, double g=0.0, double b=0.0, double a=1.0)
Definition: types.h:85
bool operator==(const GenericColorHSVA &other) const
Definition: types.h:69
GenericColorRGBA(T r, T g, T b, T a)
Definition: types.h:46


color_util
Author(s):
autogenerated on Sun Jan 10 2021 04:08:24