TrueReality  v0.1.1912
Vec2s.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/Vec2s>
30 
31 #include <iostream>
32 #include <string>
33 
34 namespace trBase
35 {
40  {
41  public:
42 
44  using value_type = short;
45 
46  const static int NUM_OF_COMPONENTS;
47 
51  Vec2s();
52 
60 
66  Vec2s(const osg::Vec2s &v);
67 
71  const osg::Vec2s& 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 Vec2s& to, value_type alpha);
121 
131  Vec2s Lerp(const Vec2s& from, const Vec2s& to, value_type alpha);
132 
142  std::string ToString(int precision = -1);
143 
147  value_type* Ptr();
148 
152  const value_type* Ptr() const;
153 
157  value_type& operator [] (int i);
158 
162  value_type operator [] (int i) const;
163 
167  void operator = (const Vec2s& v);
168 
172  void operator = (const osg::Vec2s& v);
173 
177  bool operator == (const Vec2s& v) const;
178 
182  bool operator != (const Vec2s& v) const;
183 
187  bool operator < (const Vec2s& v) const;
188 
192  bool operator > (const Vec2s& v) const;
193 
197  value_type operator * (const Vec2s& rhs) const;
198 
202  const Vec2s operator * (value_type rhs) const;
203 
207  Vec2s& operator *= (value_type rhs);
208 
212  const Vec2s operator / (value_type rhs) const;
213 
217  Vec2s& operator /= (value_type rhs);
218 
222  const Vec2s operator + (const Vec2s& rhs) const;
223 
228  Vec2s& operator += (const Vec2s& rhs);
229 
233  const Vec2s operator - (const Vec2s& rhs) const;
234 
238  Vec2s& operator -= (const Vec2s& rhs);
239 
243  const Vec2s operator - () const;
244 
248  operator osg::Vec2s() const;
249 
253  operator osg::Vec2s& ();
254 
258  operator const osg::Vec2s& () const;
259 
263  operator osg::Vec2s* ();
264 
265  protected:
266 
267  osg::Vec2s mVec;
268  };
269 
278  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2s& vec);
279 
283  TR_BASE_EXPORT Vec2s ComponentMultiply(const Vec2s& lhs, const Vec2s& rhs);
284 
288  TR_BASE_EXPORT Vec2s ComponentDivide(const Vec2s& lhs, const Vec2s& rhs);
289 }
#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.
General purpose 2D short Vector.
Definition: Vec2s.h:39
short value_type
Data type of vector components.
Definition: Vec2s.h:44
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
static const int NUM_OF_COMPONENTS
Definition: Vec2s.h:46
osg::Vec2s mVec
Definition: Vec2s.h:267