HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vec3i.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_VEC3I_H
12 #define PXR_BASE_GF_VEC3I_H
13 
14 /// \file gf/vec3i.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 GfVec3i;
31 
32 template <>
33 struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
34 
35 /// \class GfVec3i
36 /// \ingroup group_gf_LinearAlgebra
37 ///
38 /// Basic type for a vector of 3 int components.
39 ///
40 /// Represents a vector of 3 components of type \c int.
41 /// It is intended to be fast and simple.
42 ///
43 class GfVec3i
44 {
45 public:
46  /// Scalar element type and dimension.
47  typedef int ScalarType;
48  static const size_t dimension = 3;
49 
50  /// GfVec3i value-initializes to zero and performs no default
51  /// initialization, like float or double.
52  GfVec3i() = default;
53 
54  /// Initialize all elements to a single value.
55  constexpr explicit GfVec3i(int value)
56  : _data{ value, value, value }
57  {
58  }
59 
60  /// Initialize all elements with explicit arguments.
61  constexpr GfVec3i(int s0, int s1, int s2)
62  : _data{ s0, s1, s2 }
63  {
64  }
65 
66  /// Construct with pointer to values.
67  template <class Scl>
68  constexpr explicit GfVec3i(Scl const *p)
69  : _data{ p[0], p[1], p[2] }
70  {
71  }
72 
73  /// Create a unit vector along the X-axis.
74  static GfVec3i XAxis() {
75  GfVec3i result(0);
76  result[0] = 1;
77  return result;
78  }
79  /// Create a unit vector along the Y-axis.
80  static GfVec3i YAxis() {
81  GfVec3i result(0);
82  result[1] = 1;
83  return result;
84  }
85  /// Create a unit vector along the Z-axis.
86  static GfVec3i ZAxis() {
87  GfVec3i result(0);
88  result[2] = 1;
89  return result;
90  }
91 
92  /// Create a unit vector along the i-th axis, zero-based. Return the zero
93  /// vector if \p i is greater than or equal to 3.
94  static GfVec3i Axis(size_t i) {
95  GfVec3i result(0);
96  if (i < 3)
97  result[i] = 1;
98  return result;
99  }
100 
101  /// Set all elements with passed arguments.
102  GfVec3i &Set(int s0, int s1, int s2) {
103  _data[0] = s0;
104  _data[1] = s1;
105  _data[2] = s2;
106  return *this;
107  }
108 
109  /// Set all elements with a pointer to data.
110  GfVec3i &Set(int const *a) {
111  return Set(a[0], a[1], a[2]);
112  }
113 
114  /// Direct data access.
115  int const *data() const { return _data; }
116  int *data() { return _data; }
117  int const *GetArray() const { return data(); }
118 
119  /// Indexing.
120  int const &operator[](size_t i) const { return _data[i]; }
121  int &operator[](size_t i) { return _data[i]; }
122 
123  /// Hash.
124  friend inline size_t hash_value(GfVec3i const &vec) {
125  return TfHash::Combine(vec[0], vec[1], vec[2]);
126  }
127 
128  /// Equality comparison.
129  bool operator==(GfVec3i const &other) const {
130  return _data[0] == other[0] &&
131  _data[1] == other[1] &&
132  _data[2] == other[2];
133  }
134  bool operator!=(GfVec3i const &other) const {
135  return !(*this == other);
136  }
137 
138  // TODO Add inequality for other vec types...
139  /// Equality comparison.
140  GF_API
141  bool operator==(class GfVec3d const &other) const;
142  /// Equality comparison.
143  GF_API
144  bool operator==(class GfVec3f const &other) const;
145  /// Equality comparison.
146  GF_API
147  bool operator==(class GfVec3h const &other) const;
148 
149  /// Create a vec with negated elements.
150  GfVec3i operator-() const {
151  return GfVec3i(-_data[0], -_data[1], -_data[2]);
152  }
153 
154  /// Addition.
155  GfVec3i &operator+=(GfVec3i const &other) {
156  _data[0] += other[0];
157  _data[1] += other[1];
158  _data[2] += other[2];
159  return *this;
160  }
161  friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
162  return GfVec3i(l) += r;
163  }
164 
165  /// Subtraction.
166  GfVec3i &operator-=(GfVec3i const &other) {
167  _data[0] -= other[0];
168  _data[1] -= other[1];
169  _data[2] -= other[2];
170  return *this;
171  }
172  friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
173  return GfVec3i(l) -= r;
174  }
175 
176  /// Multiplication by scalar.
177  GfVec3i &operator*=(double s) {
178  _data[0] *= s;
179  _data[1] *= s;
180  _data[2] *= s;
181  return *this;
182  }
183  GfVec3i operator*(double s) const {
184  return GfVec3i(*this) *= s;
185  }
186  friend GfVec3i operator*(double s, GfVec3i const &v) {
187  return v * s;
188  }
189 
190  /// Division by scalar.
192  _data[0] /= s;
193  _data[1] /= s;
194  _data[2] /= s;
195  return *this;
196  }
197  GfVec3i operator/(int s) const {
198  return GfVec3i(*this) /= s;
199  }
200 
201  /// See GfDot().
202  int operator*(GfVec3i const &v) const {
203  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
204  }
205 
206  /// Returns the projection of \p this onto \p v. That is:
207  /// \code
208  /// v * (*this * v)
209  /// \endcode
210  GfVec3i GetProjection(GfVec3i const &v) const {
211  return v * (*this * v);
212  }
213 
214  /// Returns the orthogonal complement of \p this->GetProjection(b).
215  /// That is:
216  /// \code
217  /// *this - this->GetProjection(b)
218  /// \endcode
219  GfVec3i GetComplement(GfVec3i const &b) const {
220  return *this - this->GetProjection(b);
221  }
222 
223  /// Squared length.
224  int GetLengthSq() const {
225  return *this * *this;
226  }
227 
228 
229 private:
230  int _data[3];
231 };
232 
233 /// Output a GfVec3i.
234 /// \ingroup group_gf_DebuggingOutput
235 GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
236 
237 
238 /// Returns component-wise multiplication of vectors \p v1 and \p v2.
239 inline GfVec3i
240 GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
241  return GfVec3i(
242  v1[0] * v2[0],
243  v1[1] * v2[1],
244  v1[2] * v2[2]
245  );
246 }
247 
248 /// Returns component-wise quotient of vectors \p v1 and \p v2.
249 inline GfVec3i
250 GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
251  return GfVec3i(
252  v1[0] / v2[0],
253  v1[1] / v2[1],
254  v1[2] / v2[2]
255  );
256 }
257 
258 /// Returns the dot (inner) product of two vectors.
259 inline int
260 GfDot(GfVec3i const &v1, GfVec3i const &v2) {
261  return v1 * v2;
262 }
263 
264 
266 
267 #endif // PXR_BASE_GF_VEC3I_H
GfVec3i & operator/=(int s)
Division by scalar.
Definition: vec3i.h:191
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition: vec3i.h:80
int GetLengthSq() const
Squared length.
Definition: vec3i.h:224
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition: vec3i.h:61
static GfVec3i Axis(size_t i)
Definition: vec3i.h:94
*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
int * data()
Definition: vec3i.h:116
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition: vec3i.h:124
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition: vec3i.h:102
const GLdouble * v
Definition: glcorearb.h:837
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec3i.h:86
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition: vec3i.h:166
Definition: vec3f.h:45
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
int & operator[](size_t i)
Definition: vec3i.h:121
**But if you need a result
Definition: thread.h:622
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GfVec3i GetComplement(GfVec3i const &b) const
Definition: vec3i.h:219
constexpr GfVec3i(int value)
Initialize all elements to a single value.
Definition: vec3i.h:55
GfVec3i GfCompMult(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec3i.h:240
bool operator!=(GfVec3i const &other) const
Definition: vec3i.h:134
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec3i.h:110
int ScalarType
Scalar element type and dimension.
Definition: vec3i.h:47
int operator*(GfVec3i const &v) const
See GfDot().
Definition: vec3i.h:202
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition: vec3i.h:74
int const * data() const
Direct data access.
Definition: vec3i.h:115
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition: vec3i.h:177
GfVec3i GfCompDiv(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec3i.h:250
Definition: vec3i.h:43
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GF_API std::ostream & operator<<(std::ostream &, GfVec3i const &)
GfVec3i()=default
static const size_t dimension
Definition: vec3i.h:48
friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r)
Definition: vec3i.h:172
GfVec3i operator*(double s) const
Definition: vec3i.h:183
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
friend GfVec3i operator*(double s, GfVec3i const &v)
Definition: vec3i.h:186
GfVec3i operator-() const
Create a vec with negated elements.
Definition: vec3i.h:150
Definition: vec3d.h:45
GLfloat GLfloat v1
Definition: glcorearb.h:817
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
int GfDot(GfVec3i const &v1, GfVec3i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec3i.h:260
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition: vec3i.h:129
GLboolean r
Definition: glcorearb.h:1222
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition: vec3i.h:68
friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r)
Definition: vec3i.h:161
Definition: vec3h.h:46
GfVec3i GetProjection(GfVec3i const &v) const
Definition: vec3i.h:210
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition: vec3i.h:155
int const * GetArray() const
Definition: vec3i.h:117
#define GF_API
Definition: api.h:23
int const & operator[](size_t i) const
Indexing.
Definition: vec3i.h:120
GfVec3i operator/(int s) const
Definition: vec3i.h:197