OpenSceneGraph 3.6.5
Vec2d
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_VEC2D
15#define OSG_VEC2D 1
16
17#include <osg/Vec2f>
18
19namespace osg {
20
27
28class Vec2d
29{
30 public:
31
33 typedef double value_type;
34
36 enum { num_components = 2 };
37
39
41 Vec2d() {_v[0]=0.0; _v[1]=0.0;}
42
44
45 inline Vec2d(const Vec2f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; }
46
47 inline operator Vec2f() const { return Vec2f(static_cast<float>(_v[0]),static_cast<float>(_v[1]));}
48
49
50 inline bool operator == (const Vec2d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
51
52 inline bool operator != (const Vec2d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
53
54 inline bool operator < (const Vec2d& v) const
55 {
56 if (_v[0]<v._v[0]) return true;
57 else if (_v[0]>v._v[0]) return false;
58 else return (_v[1]<v._v[1]);
59 }
60
61 inline value_type* ptr() { return _v; }
62 inline const value_type* ptr() const { return _v; }
63
64 inline void set( value_type x, value_type y ) { _v[0]=x; _v[1]=y; }
65
66 inline value_type& operator [] (int i) { return _v[i]; }
67 inline value_type operator [] (int i) const { return _v[i]; }
68
69 inline value_type& x() { return _v[0]; }
70 inline value_type& y() { return _v[1]; }
71
72 inline value_type x() const { return _v[0]; }
73 inline value_type y() const { return _v[1]; }
74
76 inline bool valid() const { return !isNaN(); }
78 inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
79
81 inline value_type operator * (const Vec2d& rhs) const
82 {
83 return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
84 }
85
87 inline const Vec2d operator * (value_type rhs) const
88 {
89 return Vec2d(_v[0]*rhs, _v[1]*rhs);
90 }
91
94 {
95 _v[0]*=rhs;
96 _v[1]*=rhs;
97 return *this;
98 }
99
101 inline const Vec2d operator / (value_type rhs) const
102 {
103 return Vec2d(_v[0]/rhs, _v[1]/rhs);
104 }
105
108 {
109 _v[0]/=rhs;
110 _v[1]/=rhs;
111 return *this;
112 }
113
115 inline const Vec2d operator + (const Vec2d& rhs) const
116 {
117 return Vec2d(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
118 }
119
123 inline Vec2d& operator += (const Vec2d& rhs)
124 {
125 _v[0] += rhs._v[0];
126 _v[1] += rhs._v[1];
127 return *this;
128 }
129
131 inline const Vec2d operator - (const Vec2d& rhs) const
132 {
133 return Vec2d(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
134 }
135
137 inline Vec2d& operator -= (const Vec2d& rhs)
138 {
139 _v[0]-=rhs._v[0];
140 _v[1]-=rhs._v[1];
141 return *this;
142 }
143
145 inline const Vec2d operator - () const
146 {
147 return Vec2d (-_v[0], -_v[1]);
148 }
149
151 inline value_type length() const
152 {
153 return sqrt( _v[0]*_v[0] + _v[1]*_v[1] );
154 }
155
157 inline value_type length2( void ) const
158 {
159 return _v[0]*_v[0] + _v[1]*_v[1];
160 }
161
166 {
167 value_type norm = Vec2d::length();
168 if (norm>0.0)
169 {
170 value_type inv = 1.0/norm;
171 _v[0] *= inv;
172 _v[1] *= inv;
173 }
174 return( norm );
175 }
176
177}; // end of class Vec2d
178
179
181inline Vec2d componentMultiply(const Vec2d& lhs, const Vec2d& rhs)
182{
183 return Vec2d(lhs[0]*rhs[0], lhs[1]*rhs[1]);
184}
185
187inline Vec2d componentDivide(const Vec2d& lhs, const Vec2d& rhs)
188{
189 return Vec2d(lhs[0]/rhs[0], lhs[1]/rhs[1]);
190}
191
192} // end of namespace osg
193#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
divide rhs components by rhs vector components.
Definition Vec2d:187
bool isNaN(float v)
Definition Math:133
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
multiply by vector components.
Definition Vec2d:181
General purpose double pair, uses include representation of texture coordinates.
Definition Vec2d:29
bool isNaN() const
Returns true if at least one component has value NaN.
Definition Vec2d:78
Vec2d & operator/=(value_type rhs)
Unary divide by scalar.
Definition Vec2d:107
value_type length() const
Length of the vector = sqrt( vec .
Definition Vec2d:151
const Vec2d operator/(value_type rhs) const
Divide by scalar.
Definition Vec2d:101
bool operator!=(const Vec2d &v) const
Definition Vec2d:52
bool operator==(const Vec2d &v) const
Definition Vec2d:50
value_type * ptr()
Definition Vec2d:61
Vec2d(value_type x, value_type y)
Definition Vec2d:43
Vec2d(const Vec2f &vec)
Definition Vec2d:45
const Vec2d operator-() const
Negation operator.
Definition Vec2d:145
value_type x() const
Definition Vec2d:72
value_type & operator[](int i)
Definition Vec2d:66
value_type _v[2]
Definition Vec2d:38
value_type operator*(const Vec2d &rhs) const
Dot product.
Definition Vec2d:81
Vec2d()
Constructor that sets all components of the vector to zero.
Definition Vec2d:41
Vec2d & operator-=(const Vec2d &rhs)
Unary vector subtract.
Definition Vec2d:137
@ num_components
Definition Vec2d:36
bool operator<(const Vec2d &v) const
Definition Vec2d:54
value_type & y()
Definition Vec2d:70
value_type y() const
Definition Vec2d:73
value_type & x()
Definition Vec2d:69
Vec2d & operator*=(value_type rhs)
Unary multiply by scalar.
Definition Vec2d:93
bool valid() const
Returns true if all components have values that are not NaN.
Definition Vec2d:76
Vec2d & operator+=(const Vec2d &rhs)
Unary vector add.
Definition Vec2d:123
value_type length2(void) const
Length squared of the vector = vec .
Definition Vec2d:157
value_type normalize()
Normalize the vector so that it has length unity.
Definition Vec2d:165
void set(value_type x, value_type y)
Definition Vec2d:64
const value_type * ptr() const
Definition Vec2d:62
double value_type
Data type of vector components.
Definition Vec2d:33
const Vec2d operator+(const Vec2d &rhs) const
Binary vector add.
Definition Vec2d:115
General purpose float pair.
Definition Vec2f:29
value_type _v[2]
Vec member variable.
Definition Vec2f:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.