TrueReality  v0.1.1912
Vec2d.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/Vec2d>
30 
31 #include <iostream>
32 #include <string>
33 
35 namespace osg
36 {
37  class Vec2f;
38 }
40 
41 namespace trBase
42 {
43  class Vec2f;
44 
49  {
50  public:
51 
53  using value_type = double;
54 
55  const static int NUM_OF_COMPONENTS;
56 
60  Vec2d();
61 
69 
75  Vec2d(const osg::Vec2d &v);
76 
82  Vec2d(const osg::Vec2f &v);
83 
87  const osg::Vec2d& GetOSGVector() const;
88 
92  value_type Length() const;
93 
97  value_type Length2() const;
98 
103  value_type Normalize();
104 
108  value_type& X();
109 
113  value_type& Y();
114 
118  value_type X() const;
119 
123  value_type Y() const;
124 
128  void Set(value_type x, value_type y);
129 
136  void Lerp(const Vec2d& to, value_type alpha);
137 
147  Vec2d Lerp(const Vec2d& from, const Vec2d& to, value_type alpha);
148 
156  std::string ToString(int precision = -1);
157 
161  value_type* Ptr();
162 
166  const value_type* Ptr() const;
167 
171  value_type& operator [] (int i);
172 
176  value_type operator [] (int i) const;
177 
181  void operator = (const Vec2d& v);
182 
186  void operator = (const Vec2f& v);
187 
191  void operator = (const osg::Vec2d& v);
192 
196  bool operator == (const Vec2d& v) const;
197 
201  bool operator != (const Vec2d& v) const;
202 
206  bool operator < (const Vec2d& v) const;
207 
211  bool operator > (const Vec2d& v) const;
212 
216  value_type operator * (const Vec2d& rhs) const;
217 
221  const Vec2d operator * (value_type rhs) const;
222 
226  Vec2d& operator *= (value_type rhs);
227 
231  const Vec2d operator / (value_type rhs) const;
232 
236  Vec2d& operator /= (value_type rhs);
237 
241  const Vec2d operator + (const Vec2d& rhs) const;
242 
247  Vec2d& operator += (const Vec2d& rhs);
248 
252  const Vec2d operator - (const Vec2d& rhs) const;
253 
257  Vec2d& operator -= (const Vec2d& rhs);
258 
262  const Vec2d operator - () const;
263 
267  operator osg::Vec2d () const;
268 
272  operator osg::Vec2d& ();
273 
277  operator const osg::Vec2d& () const;
278 
282  operator osg::Vec2d* ();
283 
284  protected:
285 
286  osg::Vec2d mVec;
287  };
288 
297  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2d& vec);
298 
302  TR_BASE_EXPORT Vec2d ComponentMultiply(const Vec2d& lhs, const Vec2d& rhs);
303 
307  TR_BASE_EXPORT Vec2d ComponentDivide(const Vec2d& lhs, const Vec2d& rhs);
308 }
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
std::string operator+(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:193
General purpose 2D float Vector.
Definition: Vec2f.h:48
TR_BASE_EXPORT Vec2d ComponentDivide(const Vec2d &lhs, const Vec2d &rhs)
Divide rhs components by rhs vector components.
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
General purpose 2D double Vector.
Definition: Vec2d.h:48
std::string ToString(const T &t, int precision=-1)
A utility function to convert a basic type into a string.
Definition: StringUtils.h:334
double value_type
Data type of vector components.
Definition: Vec2d.h:53
osg::Vec2d mVec
Definition: Vec2d.h:286
T Lerp(T from, T to, T alpha)
Linear Interpolation function.
Definition: Math.h:191
Definition: FrameStamp.h:37
static const int NUM_OF_COMPONENTS
Definition: Vec2d.h:55
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Vec2d &vec)
Stream insertion operator.
TR_BASE_EXPORT Vec2d ComponentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Multiply individual vector components.