TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unorm16.h
Go to the documentation of this file.
1 
12 #ifndef G3D_unorm16_h
13 #define G3D_unorm16_h
14 
15 #include "G3D/platform.h"
16 #include "G3D/g3dmath.h"
17 
18 namespace G3D {
19 
20 
33 private:
34  uint16 m_bits;
35 
38  explicit unorm16(uint16 b) : m_bits(b) {}
39 
40 public:
41 
43  static unorm16 fromBits(uint16 b) {
44  return unorm16(b);
45  }
46 
49  return unorm16(b);
50  }
51 
52  unorm16() : m_bits(0) {}
53 
54  unorm16(const unorm16& other) : m_bits(other.m_bits) {}
55 
56  explicit unorm16(const class Any& a);
57 
58  class Any toAny() const;
59 
61  explicit unorm16(float f) {
62  m_bits = uint16(clamp(f, 0.0f, 1.0f) * 65535.0f + 0.5f);
63  }
64 
65  explicit unorm16(double f) {
66  m_bits = uint16(clamp(f, 0.0, 1.0) * 65535.0 + 0.5);
67  }
68 
70  operator float() const {
71  return float(m_bits) * (1.0f / 65535.0f);
72  }
73 
74  operator double() const {
75  return double(m_bits) * (1.0 / 65535.0);
76  }
77 
78  static unorm16 one() {
79  return fromBits(65535);
80  }
81 
82  static unorm16 zero() {
83  return fromBits(0);
84  }
85 
89  uint16 bits() const {
90  return m_bits;
91  }
92 
95  return m_bits;
96  }
97 
98  bool operator>(const unorm16 other) const {
99  return m_bits > other.m_bits;
100  }
101 
102  bool operator<(const unorm16 other) const {
103  return m_bits < other.m_bits;
104  }
105 
106  bool operator>=(const unorm16 other) const {
107  return m_bits >= other.m_bits;
108  }
109 
110  bool operator<=(const unorm16 other) const {
111  return m_bits <= other.m_bits;
112  }
113 
114  bool operator==(const unorm16 other) const {
115  return m_bits <= other.m_bits;
116  }
117 
118  bool operator!=(const unorm16 other) const {
119  return m_bits != other.m_bits;
120  }
121 
122  unorm16 operator+(const unorm16 other) const {
123  return unorm16(uint16(m_bits + other.m_bits));
124  }
125 
126  unorm16& operator+=(const unorm16 other) {
127  m_bits += other.m_bits;
128  return *this;
129  }
130 
131  unorm16 operator-(const unorm16 other) const {
132  return unorm16(uint16(m_bits - other.m_bits));
133  }
134 
135  unorm16& operator-=(const unorm16 other) {
136  m_bits -= other.m_bits;
137  return *this;
138  }
139 
140  unorm16 operator*(const int i) const {
141  return unorm16(uint16(m_bits * i));
142  }
143 
144  unorm16& operator*=(const int i) {
145  m_bits *= i;
146  return *this;
147  }
148 
149  unorm16 operator/(const int i) const {
150  return unorm16(uint16(m_bits / i));
151  }
152 
153  unorm16& operator/=(const int i) {
154  m_bits /= i;
155  return *this;
156  }
157 
158  unorm16 operator<<(const int i) const {
159  return unorm16((uint16)(m_bits << i));
160  }
161 
162  unorm16& operator<<=(const int i) {
163  m_bits <<= i;
164  return *this;
165  }
166 
167  unorm16 operator>>(const int i) const {
168  return unorm16(uint16(m_bits >> i));
169  }
170 
171  unorm16& operator>>=(const int i) {
172  m_bits >>= i;
173  return *this;
174  }
175 }
177 
178 } // namespace G3D
179 
180 #endif // G3D_unorm16
unorm16 & operator>>=(const int i)
Definition: unorm16.h:171
unorm16 operator-(const unorm16 other) const
Definition: unorm16.h:131
class Any toAny() const
unorm16 & operator+=(const unorm16 other)
Definition: unorm16.h:126
unorm16 & operator<<=(const int i)
Definition: unorm16.h:162
unorm16 & operator/=(const int i)
Definition: unorm16.h:153
bool operator!=(const NetAddress &a, const NetAddress &b)
Definition: NetAddress.h:128
bool operator<=(const unorm16 other) const
Definition: unorm16.h:110
static unorm16 fromBits(uint16 b)
Definition: unorm16.h:43
Definition: AABox.h:25
unorm16 operator+(const unorm16 other) const
Definition: unorm16.h:122
static unorm16 reinterpretFrom(uint16 b)
Definition: unorm16.h:48
bool operator<(const unorm16 other) const
Definition: unorm16.h:102
double clamp(double val, double low, double hi)
Definition: g3dmath.h:571
G3D::Color3 operator/(float s, const G3D::Color3 &c)
Definition: Color3.h:287
bool operator==(const NetAddress &a, const NetAddress &b)
Definition: NetAddress.h:123
uint16_t uint16
Definition: g3dmath.h:166
unorm16
Definition: unorm16.h:32
static unorm16 one()
Definition: unorm16.h:78
unorm16 & operator-=(const unorm16 other)
Definition: unorm16.h:135
#define G3D_END_PACKED_CLASS(byteAlign)
Definition: platform.h:357
unorm16 & operator*=(const int i)
Definition: unorm16.h:144
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
bool operator>=(const unorm16 other) const
Definition: unorm16.h:106
bool operator>(const unorm16 other) const
Definition: unorm16.h:98
#define G3D_BEGIN_PACKED_CLASS(byteAlign)
Definition: platform.h:345
std::ostream & operator<<(std::ostream &os, const NetAddress &)
Definition: NetworkDevice.cpp:26
unorm16 operator>>(const int i) const
Definition: unorm16.h:167
static unorm16 zero()
Definition: unorm16.h:82
#define const
Definition: zconf.h:217
G3D::Color3 operator*(float s, const G3D::Color3 &c)
Definition: Color3.h:275
uint16 reinterpretAsUInt16() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:94