OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec2b.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_VEC2B
15 #define OSG_VEC2B 1
16 
17 namespace osg {
18 
25 class Vec2b
26 {
27  public:
28 
29  // Methods are defined here so that they are implicitly inlined
30 
32  typedef signed char value_type;
33 
35  enum { num_components = 2 };
36 
38  value_type _v[2];
39 
41  Vec2b() { _v[0]=0; _v[1]=0; }
42 
43  Vec2b(value_type r, value_type g)
44  {
45  _v[0]=r; _v[1]=g;
46  }
47 
48  inline bool operator == (const Vec2b& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
49 
50  inline bool operator != (const Vec2b& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
51 
52  inline bool operator < (const Vec2b& v) const
53  {
54  if (_v[0]<v._v[0]) return true;
55  else if (_v[0]>v._v[0]) return false;
56  else return (_v[1]<v._v[1]);
57  }
58 
59  inline value_type* ptr() { return _v; }
60  inline const value_type* ptr() const { return _v; }
61 
62  inline void set( value_type x, value_type y)
63  {
64  _v[0]=x; _v[1]=y;
65  }
66 
67  inline void set( const Vec2b& rhs)
68  {
69  _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
70  }
71 
72  inline value_type& operator [] (int i) { return _v[i]; }
73  inline value_type operator [] (int i) const { return _v[i]; }
74 
75  inline value_type& x() { return _v[0]; }
76  inline value_type& y() { return _v[1]; }
77 
78  inline value_type x() const { return _v[0]; }
79  inline value_type y() const { return _v[1]; }
80 
81  inline value_type& r() { return _v[0]; }
82  inline value_type& g() { return _v[1]; }
83 
84  inline value_type r() const { return _v[0]; }
85  inline value_type g() const { return _v[1]; }
86 
88  inline Vec2b operator * (float rhs) const
89  {
90  Vec2b col(*this);
91  col *= rhs;
92  return col;
93  }
94 
96  inline Vec2b& operator *= (float rhs)
97  {
98  _v[0]=(value_type)((float)_v[0]*rhs);
99  _v[1]=(value_type)((float)_v[1]*rhs);
100  return *this;
101  }
102 
104  inline Vec2b operator / (float rhs) const
105  {
106  Vec2b col(*this);
107  col /= rhs;
108  return col;
109  }
110 
112  inline Vec2b& operator /= (float rhs)
113  {
114  float div = 1.0f/rhs;
115  *this *= div;
116  return *this;
117  }
118 
120  inline Vec2b operator + (const Vec2b& rhs) const
121  {
122  return Vec2b(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
123  }
124 
128  inline Vec2b& operator += (const Vec2b& rhs)
129  {
130  _v[0] += rhs._v[0];
131  _v[1] += rhs._v[1];
132  return *this;
133  }
134 
136  inline Vec2b operator - (const Vec2b& rhs) const
137  {
138  return Vec2b(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
139  }
140 
142  inline Vec2b& operator -= (const Vec2b& rhs)
143  {
144  _v[0]-=rhs._v[0];
145  _v[1]-=rhs._v[1];
146  return *this;
147  }
148 
149 }; // end of class Vec2b
150 
151 
152 
153 } // end of namespace osg
154 
155 #endif
Vec2b & operator-=(const Vec2b &rhs)
Definition: Vec2b.h:142
value_type g() const
Definition: Vec2b.h:85
value_type & g()
Definition: Vec2b.h:82
value_type r() const
Definition: Vec2b.h:84
Vec2b()
Definition: Vec2b.h:41
void set(value_type x, value_type y)
Definition: Vec2b.h:62
Vec2b & operator+=(const Vec2b &rhs)
Definition: Vec2b.h:128
bool operator<(const Vec2b &v) const
Definition: Vec2b.h:52
Vec2b operator+(const Vec2b &rhs) const
Definition: Vec2b.h:120
const value_type * ptr() const
Definition: Vec2b.h:60
Vec2b & operator*=(float rhs)
Definition: Vec2b.h:96
value_type & x()
Definition: Vec2b.h:75
value_type x() const
Definition: Vec2b.h:78
value_type & operator[](int i)
Definition: Vec2b.h:72
value_type * ptr()
Definition: Vec2b.h:59
Vec2b operator/(float rhs) const
Definition: Vec2b.h:104
Vec2b & operator/=(float rhs)
Definition: Vec2b.h:112
bool operator==(const Vec2b &v) const
Definition: Vec2b.h:48
value_type & y()
Definition: Vec2b.h:76
Vec2b operator*(float rhs) const
Definition: Vec2b.h:88
Vec2b operator-(const Vec2b &rhs) const
Definition: Vec2b.h:136
value_type _v[2]
Definition: Vec2b.h:38
signed char value_type
Definition: Vec2b.h:32
value_type & r()
Definition: Vec2b.h:81
Definition: AlphaFunc.h:19
value_type y() const
Definition: Vec2b.h:79
Vec2b(value_type r, value_type g)
Definition: Vec2b.h:43
void set(const Vec2b &rhs)
Definition: Vec2b.h:67
bool operator!=(const Vec2b &v) const
Definition: Vec2b.h:50