OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec2s.h
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_VEC2S
15 #define OSG_VEC2S 1
16 
17 namespace osg {
18 
19 class Vec2s
20 {
21  public:
22 
24  typedef short value_type;
25 
27  enum { num_components = 2 };
28 
29  value_type _v[2];
30 
32  Vec2s() { _v[0]=0; _v[1]=0; }
33 
34  Vec2s(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
35 
36  inline bool operator == (const Vec2s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
37  inline bool operator != (const Vec2s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
38  inline bool operator < (const Vec2s& v) const
39  {
40  if (_v[0]<v._v[0]) return true;
41  else if (_v[0]>v._v[0]) return false;
42  else return (_v[1]<v._v[1]);
43  }
44 
45  inline value_type* ptr() { return _v; }
46  inline const value_type* ptr() const { return _v; }
47 
48  inline void set( value_type x, value_type y)
49  {
50  _v[0]=x; _v[1]=y;
51  }
52 
53  inline void set( const Vec2s& rhs)
54  {
55  _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
56  }
57 
58  inline value_type& operator [] (int i) { return _v[i]; }
59  inline value_type operator [] (int i) const { return _v[i]; }
60 
61  inline value_type& x() { return _v[0]; }
62  inline value_type& y() { return _v[1]; }
63 
64  inline value_type x() const { return _v[0]; }
65  inline value_type y() const { return _v[1]; }
66 
67  inline value_type& r() { return _v[0]; }
68  inline value_type& g() { return _v[1]; }
69 
70  inline value_type r() const { return _v[0]; }
71  inline value_type g() const { return _v[1]; }
72 
73  inline Vec2s operator * (value_type rhs) const
74  {
75  return Vec2s(_v[0]*rhs, _v[1]*rhs);
76  }
77 
78  inline Vec2s& operator *= (value_type rhs)
79  {
80  _v[0]*=rhs;
81  _v[1]*=rhs;
82  return *this;
83  }
84 
85  inline Vec2s operator / (value_type rhs) const
86  {
87  return Vec2s(_v[0]/rhs, _v[1]/rhs);
88  }
89 
90  inline Vec2s& operator /= (value_type rhs)
91  {
92  _v[0]/=rhs;
93  _v[1]/=rhs;
94  return *this;
95  }
96 
97  inline Vec2s operator * (const Vec2s& rhs) const
98  {
99  return Vec2s(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
100  }
101 
102  inline Vec2s operator + (const Vec2s& rhs) const
103  {
104  return Vec2s(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
105  }
106 
107  inline Vec2s& operator += (const Vec2s& rhs)
108  {
109  _v[0] += rhs._v[0];
110  _v[1] += rhs._v[1];
111  return *this;
112  }
113 
114  inline Vec2s operator - (const Vec2s& rhs) const
115  {
116  return Vec2s(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
117  }
118 
119  inline Vec2s& operator -= (const Vec2s& rhs)
120  {
121  _v[0]-=rhs._v[0];
122  _v[1]-=rhs._v[1];
123  return *this;
124  }
125 
126 
127  inline Vec2s operator - () const
128  {
129  return Vec2s (-_v[0], -_v[1]);
130  }
131 
132 
133 }; // end of class Vec2s
134 
135 
137 inline Vec2s componentMultiply(const Vec2s& lhs, const Vec2s& rhs)
138 {
139  return Vec2s(lhs[0]*rhs[0], lhs[1]*rhs[1]);
140 }
141 
143 inline Vec2s componentDivide(const Vec2s& lhs, const Vec2s& rhs)
144 {
145  return Vec2s(lhs[0]/rhs[0], lhs[1]/rhs[1]);
146 }
147 
148 } // end of namespace osg
149 #endif
short value_type
Definition: Vec2s.h:24
value_type & g()
Definition: Vec2s.h:68
Vec2s & operator+=(const Vec2s &rhs)
Definition: Vec2s.h:107
value_type & x()
Definition: Vec2s.h:61
Vec2s()
Definition: Vec2s.h:32
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:187
value_type & r()
Definition: Vec2s.h:67
Vec2s operator*(value_type rhs) const
Definition: Vec2s.h:73
value_type & operator[](int i)
Definition: Vec2s.h:58
value_type y() const
Definition: Vec2s.h:65
Vec2s & operator/=(value_type rhs)
Definition: Vec2s.h:90
Vec2s operator-() const
Definition: Vec2s.h:127
const value_type * ptr() const
Definition: Vec2s.h:46
bool operator==(const Vec2s &v) const
Definition: Vec2s.h:36
value_type r() const
Definition: Vec2s.h:70
value_type g() const
Definition: Vec2s.h:71
bool operator!=(const Vec2s &v) const
Definition: Vec2s.h:37
void set(const Vec2s &rhs)
Definition: Vec2s.h:53
Vec2s operator+(const Vec2s &rhs) const
Definition: Vec2s.h:102
Vec2s & operator-=(const Vec2s &rhs)
Definition: Vec2s.h:119
Definition: AlphaFunc.h:19
Vec2s operator/(value_type rhs) const
Definition: Vec2s.h:85
value_type x() const
Definition: Vec2s.h:64
Vec2s(value_type x, value_type y)
Definition: Vec2s.h:34
value_type & y()
Definition: Vec2s.h:62
value_type _v[2]
Definition: Vec2s.h:29
Vec2s & operator*=(value_type rhs)
Definition: Vec2s.h:78
void set(value_type x, value_type y)
Definition: Vec2s.h:48
value_type * ptr()
Definition: Vec2s.h:45
bool operator<(const Vec2s &v) const
Definition: Vec2s.h:38
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:181