TrueReality  v0.1.1912
Vec2ub.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #pragma once
23 
24 #include <trBase/Export.h>
25 
26 #include <trUtil/StringUtils.h>
27 #include <trUtil/Math.h>
28 
29 #include <osg/Vec2ub>
30 
31 #include <iostream>
32 #include <string>
33 
34 namespace trBase
35 {
40  {
41  public:
42 
44  using value_type = unsigned char;
45 
46  const static int NUM_OF_COMPONENTS;
47 
51  Vec2ub();
52 
60 
66  Vec2ub(const osg::Vec2ub &v);
67 
71  const osg::Vec2ub& GetOSGVector() const;
72 
76  value_type Length() const;
77 
81  value_type Length2() const;
82 
87  value_type Normalize();
88 
92  value_type& X();
93 
97  value_type& Y();
98 
102  value_type X() const;
103 
107  value_type Y() const;
108 
112  void Set(value_type x, value_type y);
113 
120  void Lerp(const Vec2ub& to, value_type alpha);
121 
131  Vec2ub Lerp(const Vec2ub& from, const Vec2ub& to, value_type alpha);
132 
138  std::string ToString(int precision = -1);
139 
143  value_type* Ptr();
144 
148  const value_type* Ptr() const;
149 
153  value_type& operator [] (int i);
154 
158  value_type operator [] (int i) const;
159 
163  void operator = (const Vec2ub& v);
164 
168  void operator = (const osg::Vec2ub& v);
169 
173  bool operator == (const Vec2ub& v) const;
174 
178  bool operator != (const Vec2ub& v) const;
179 
183  bool operator < (const Vec2ub& v) const;
184 
188  bool operator > (const Vec2ub& v) const;
189 
193  value_type operator * (const Vec2ub& rhs) const;
194 
198  const Vec2ub operator * (value_type rhs) const;
199 
203  Vec2ub& operator *= (value_type rhs);
204 
208  const Vec2ub operator / (value_type rhs) const;
209 
213  Vec2ub& operator /= (value_type rhs);
214 
218  const Vec2ub operator + (const Vec2ub& rhs) const;
219 
224  Vec2ub& operator += (const Vec2ub& rhs);
225 
229  const Vec2ub operator - (const Vec2ub& rhs) const;
230 
234  Vec2ub& operator -= (const Vec2ub& rhs);
235 
239  const Vec2ub operator - () const;
240 
244  operator osg::Vec2ub() const;
245 
249  operator osg::Vec2ub& ();
250 
254  operator const osg::Vec2ub& () const;
255 
259  operator osg::Vec2ub* ();
260 
261  protected:
262 
263  osg::Vec2ub mVec;
264  };
265 
274  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2ub& vec);
275 
279  TR_BASE_EXPORT Vec2ub ComponentMultiply(const Vec2ub& lhs, const Vec2ub& rhs);
280 
284  TR_BASE_EXPORT Vec2ub ComponentDivide(const Vec2ub& lhs, const Vec2ub& rhs);
285 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
std::string operator+(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:193
bool operator==(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:187
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Matrixd &q)
Stream insertion operator.
static const int NUM_OF_COMPONENTS
Definition: Vec2ub.h:46
std::string ToString(const T &t, int precision=-1)
A utility function to convert a basic type into a string.
Definition: StringUtils.h:334
TR_BASE_EXPORT Vec2b ComponentDivide(const Vec2b &lhs, const Vec2b &rhs)
Divide rhs components by rhs vector components.
TR_BASE_EXPORT Vec2b ComponentMultiply(const Vec2b &lhs, const Vec2b &rhs)
Multiply individual vector components.
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191
osg::Vec2ub mVec
Definition: Vec2ub.h:263
unsigned char value_type
Data type of vector components.
Definition: Vec2ub.h:44
General purpose 2D unsigned byte Vector.
Definition: Vec2ub.h:39