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