HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vec4i.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // This file is generated by a script. Do not edit directly. Edit the
9 // vec.template.h file to make changes.
10 
11 #ifndef PXR_BASE_GF_VEC4I_H
12 #define PXR_BASE_GF_VEC4I_H
13 
14 /// \file gf/vec4i.h
15 /// \ingroup group_gf_LinearAlgebra
16 
17 #include "pxr/pxr.h"
18 #include "pxr/base/tf/diagnostic.h"
19 #include "pxr/base/gf/api.h"
20 #include "pxr/base/gf/limits.h"
21 #include "pxr/base/gf/traits.h"
22 #include "pxr/base/tf/hash.h"
23 
24 #include <cstddef>
25 
26 #include <iosfwd>
27 
29 
30 class GfVec4i;
31 
32 template <>
33 struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
34 
35 /// \class GfVec4i
36 /// \ingroup group_gf_LinearAlgebra
37 ///
38 /// Basic type for a vector of 4 int components.
39 ///
40 /// Represents a vector of 4 components of type \c int.
41 /// It is intended to be fast and simple.
42 ///
43 class GfVec4i
44 {
45 public:
46  /// Scalar element type and dimension.
47  typedef int ScalarType;
48  static const size_t dimension = 4;
49 
50  /// GfVec4i value-initializes to zero and performs no default
51  /// initialization, like float or double.
52  GfVec4i() = default;
53 
54  /// Initialize all elements to a single value.
55  constexpr explicit GfVec4i(int value)
56  : _data{ value, value, value, value }
57  {
58  }
59 
60  /// Initialize all elements with explicit arguments.
61  constexpr GfVec4i(int s0, int s1, int s2, int s3)
62  : _data{ s0, s1, s2, s3 }
63  {
64  }
65 
66  /// Construct with pointer to values.
67  template <class Scl>
68  constexpr explicit GfVec4i(Scl const *p)
69  : _data{ p[0], p[1], p[2], p[3] }
70  {
71  }
72 
73  /// Create a unit vector along the X-axis.
74  static GfVec4i XAxis() {
75  GfVec4i result(0);
76  result[0] = 1;
77  return result;
78  }
79  /// Create a unit vector along the Y-axis.
80  static GfVec4i YAxis() {
81  GfVec4i result(0);
82  result[1] = 1;
83  return result;
84  }
85  /// Create a unit vector along the Z-axis.
86  static GfVec4i ZAxis() {
87  GfVec4i result(0);
88  result[2] = 1;
89  return result;
90  }
91  /// Create a unit vector along the W-axis.
92  static GfVec4i WAxis() {
93  GfVec4i result(0);
94  result[3] = 1;
95  return result;
96  }
97 
98  /// Create a unit vector along the i-th axis, zero-based. Return the zero
99  /// vector if \p i is greater than or equal to 4.
100  static GfVec4i Axis(size_t i) {
101  GfVec4i result(0);
102  if (i < 4)
103  result[i] = 1;
104  return result;
105  }
106 
107  /// Set all elements with passed arguments.
108  GfVec4i &Set(int s0, int s1, int s2, int s3) {
109  _data[0] = s0;
110  _data[1] = s1;
111  _data[2] = s2;
112  _data[3] = s3;
113  return *this;
114  }
115 
116  /// Set all elements with a pointer to data.
117  GfVec4i &Set(int const *a) {
118  return Set(a[0], a[1], a[2], a[3]);
119  }
120 
121  /// Direct data access.
122  int const *data() const { return _data; }
123  int *data() { return _data; }
124  int const *GetArray() const { return data(); }
125 
126  /// Indexing.
127  int const &operator[](size_t i) const { return _data[i]; }
128  int &operator[](size_t i) { return _data[i]; }
129 
130  /// Hash.
131  friend inline size_t hash_value(GfVec4i const &vec) {
132  return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]);
133  }
134 
135  /// Equality comparison.
136  bool operator==(GfVec4i const &other) const {
137  return _data[0] == other[0] &&
138  _data[1] == other[1] &&
139  _data[2] == other[2] &&
140  _data[3] == other[3];
141  }
142  bool operator!=(GfVec4i const &other) const {
143  return !(*this == other);
144  }
145 
146  // TODO Add inequality for other vec types...
147  /// Equality comparison.
148  GF_API
149  bool operator==(class GfVec4d const &other) const;
150  /// Equality comparison.
151  GF_API
152  bool operator==(class GfVec4f const &other) const;
153  /// Equality comparison.
154  GF_API
155  bool operator==(class GfVec4h const &other) const;
156 
157  /// Create a vec with negated elements.
158  GfVec4i operator-() const {
159  return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
160  }
161 
162  /// Addition.
163  GfVec4i &operator+=(GfVec4i const &other) {
164  _data[0] += other[0];
165  _data[1] += other[1];
166  _data[2] += other[2];
167  _data[3] += other[3];
168  return *this;
169  }
170  friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
171  return GfVec4i(l) += r;
172  }
173 
174  /// Subtraction.
175  GfVec4i &operator-=(GfVec4i const &other) {
176  _data[0] -= other[0];
177  _data[1] -= other[1];
178  _data[2] -= other[2];
179  _data[3] -= other[3];
180  return *this;
181  }
182  friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
183  return GfVec4i(l) -= r;
184  }
185 
186  /// Multiplication by scalar.
187  GfVec4i &operator*=(double s) {
188  _data[0] *= s;
189  _data[1] *= s;
190  _data[2] *= s;
191  _data[3] *= s;
192  return *this;
193  }
194  GfVec4i operator*(double s) const {
195  return GfVec4i(*this) *= s;
196  }
197  friend GfVec4i operator*(double s, GfVec4i const &v) {
198  return v * s;
199  }
200 
201  /// Division by scalar.
203  _data[0] /= s;
204  _data[1] /= s;
205  _data[2] /= s;
206  _data[3] /= s;
207  return *this;
208  }
209  GfVec4i operator/(int s) const {
210  return GfVec4i(*this) /= s;
211  }
212 
213  /// See GfDot().
214  int operator*(GfVec4i const &v) const {
215  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
216  }
217 
218  /// Returns the projection of \p this onto \p v. That is:
219  /// \code
220  /// v * (*this * v)
221  /// \endcode
222  GfVec4i GetProjection(GfVec4i const &v) const {
223  return v * (*this * v);
224  }
225 
226  /// Returns the orthogonal complement of \p this->GetProjection(b).
227  /// That is:
228  /// \code
229  /// *this - this->GetProjection(b)
230  /// \endcode
231  GfVec4i GetComplement(GfVec4i const &b) const {
232  return *this - this->GetProjection(b);
233  }
234 
235  /// Squared length.
236  int GetLengthSq() const {
237  return *this * *this;
238  }
239 
240 
241 private:
242  int _data[4];
243 };
244 
245 /// Output a GfVec4i.
246 /// \ingroup group_gf_DebuggingOutput
247 GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
248 
249 
250 /// Returns component-wise multiplication of vectors \p v1 and \p v2.
251 inline GfVec4i
252 GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
253  return GfVec4i(
254  v1[0] * v2[0],
255  v1[1] * v2[1],
256  v1[2] * v2[2],
257  v1[3] * v2[3]
258  );
259 }
260 
261 /// Returns component-wise quotient of vectors \p v1 and \p v2.
262 inline GfVec4i
263 GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
264  return GfVec4i(
265  v1[0] / v2[0],
266  v1[1] / v2[1],
267  v1[2] / v2[2],
268  v1[3] / v2[3]
269  );
270 }
271 
272 /// Returns the dot (inner) product of two vectors.
273 inline int
274 GfDot(GfVec4i const &v1, GfVec4i const &v2) {
275  return v1 * v2;
276 }
277 
278 
280 
281 #endif // PXR_BASE_GF_VEC4I_H
Definition: vec4i.h:43
static GfVec4i Axis(size_t i)
Definition: vec4i.h:100
friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r)
Definition: vec4i.h:170
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:127
GfVec4i GfCompMult(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec4i.h:252
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:158
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:187
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:131
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:175
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
const GLdouble * v
Definition: glcorearb.h:837
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:55
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
int const * GetArray() const
Definition: vec4i.h:124
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:80
GfVec4i GfCompDiv(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec4i.h:263
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
Definition: vec4d.h:45
int const * data() const
Direct data access.
Definition: vec4i.h:122
**But if you need a result
Definition: thread.h:622
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GfVec4i()=default
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:202
GfVec4i GetComplement(GfVec4i const &b) const
Definition: vec4i.h:231
Definition: vec4h.h:46
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:163
int & operator[](size_t i)
Definition: vec4i.h:128
GfVec4i operator*(double s) const
Definition: vec4i.h:194
static GfVec4i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec4i.h:86
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:136
GF_API std::ostream & operator<<(std::ostream &, GfVec4i const &)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GfVec4i GetProjection(GfVec4i const &v) const
Definition: vec4i.h:222
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:68
Definition: vec4f.h:45
int GfDot(GfVec4i const &v1, GfVec4i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec4i.h:274
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:108
bool operator!=(GfVec4i const &other) const
Definition: vec4i.h:142
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
friend GfVec4i operator*(double s, GfVec4i const &v)
Definition: vec4i.h:197
int * data()
Definition: vec4i.h:123
GfVec4i operator/(int s) const
Definition: vec4i.h:209
GLfloat GLfloat v1
Definition: glcorearb.h:817
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GfVec4i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec4i.h:117
friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r)
Definition: vec4i.h:182
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:74
GLboolean r
Definition: glcorearb.h:1222
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:47
static const size_t dimension
Definition: vec4i.h:48
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:214
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:61
#define GF_API
Definition: api.h:23
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:92
int GetLengthSq() const
Squared length.
Definition: vec4i.h:236