Loading...
Searching...
No Matches
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//
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
16
17#include "pxr/pxr.h"
18#include "pxr/base/gf/api.h"
19#include "pxr/base/gf/limits.h"
20#include "pxr/base/gf/traits.h"
22#include "pxr/base/tf/hash.h"
23
24#include <cstddef>
25#include <type_traits>
26
27#include <iosfwd>
28
29PXR_NAMESPACE_OPEN_SCOPE
30
31class GfVec2i;
32
33template <>
34struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
35
45{
46public:
48 typedef int ScalarType;
49 static const size_t dimension = 3;
50
62 int x, y, z;
64
67 GfVec3i() = default;
68
70 constexpr explicit GfVec3i(int value)
71 : x(value), y(value), z(value)
72 {
73 }
74
76 constexpr GfVec3i(int s0, int s1, int s2)
77 : x(s0), y(s1), z(s2)
78 {
79 }
80
82 template <class Scl>
83 constexpr explicit GfVec3i(Scl const *p)
84 : x(p[0]), y(p[1]), z(p[2])
85 {
86 }
88 static GfVec3i XAxis() {
89 GfVec3i result(0);
90 result[0] = 1;
91 return result;
92 }
93
95 static GfVec3i YAxis() {
96 GfVec3i result(0);
97 result[1] = 1;
98 return result;
99 }
100
102 static GfVec3i ZAxis() {
103 GfVec3i result(0);
104 result[2] = 1;
105 return result;
106 }
107
110 static GfVec3i Axis(size_t i) {
111 GfVec3i result(0);
112 if (i < 3)
113 result[i] = 1;
114 return result;
115 }
116
118 GfVec3i &Set(int s0, int s1, int s2) {
119 x = s0;
120 y = s1;
121 z = s2;
122 return *this;
123 }
124
126 GfVec3i &Set(int const *a) {
127 return Set(a[0], a[1], a[2]);
128 }
129
135 int const *data() const { return &x; }
136 int *data() { return &x; }
137 int const *GetArray() const { return data(); }
138
140 int const &operator[](size_t i) const { return data()[i]; }
141 int &operator[](size_t i) { return data()[i]; }
142
144 friend inline size_t hash_value(GfVec3i const &vec) {
145 return TfHash::Combine(vec.x, vec.y, vec.z);
146 }
147
149 bool operator==(GfVec3i const &other) const {
150 return x == other.x &&
151 y == other.y &&
152 z == other.z;
153 }
154 bool operator!=(GfVec3i const &other) const {
155 return !(*this == other);
156 }
157
158 // TODO Add inequality for other vec types...
160 GF_API
161 bool operator==(class GfVec3d const &other) const;
163 GF_API
164 bool operator==(class GfVec3f const &other) const;
166 GF_API
167 bool operator==(class GfVec3h const &other) const;
168
171 return GfVec3i(-x, -y, -z);
172 }
173
175 GfVec3i &operator+=(GfVec3i const &other) {
176 x += other.x;
177 y += other.y;
178 z += other.z;
179 return *this;
180 }
181 friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
182 return GfVec3i(l) += r;
183 }
184
186 GfVec3i &operator-=(GfVec3i const &other) {
187 x -= other.x;
188 y -= other.y;
189 z -= other.z;
190 return *this;
191 }
192 friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
193 return GfVec3i(l) -= r;
194 }
195
197 GfVec3i &operator*=(double s) {
198 x *= s;
199 y *= s;
200 z *= s;
201 return *this;
202 }
203 GfVec3i operator*(double s) const {
204 return GfVec3i(*this) *= s;
205 }
206 friend GfVec3i operator*(double s, GfVec3i const &v) {
207 return v * s;
208 }
209
212 x /= s;
213 y /= s;
214 z /= s;
215 return *this;
216 }
217 GfVec3i operator/(int s) const {
218 return GfVec3i(*this) /= s;
219 }
220
222 int operator*(GfVec3i const &v) const {
223 return x * v.x + y * v.y + z * v.z;
224 }
225
230 GfVec3i GetProjection(GfVec3i const &v) const {
231 return v * (*this * v);
232 }
233
239 GfVec3i GetComplement(GfVec3i const &b) const {
240 return *this - this->GetProjection(b);
241 }
242
244 int GetLengthSq() const {
245 return *this * *this;
246 }
247
248
264#if defined (doxygen)
265 constexpr GfVec2i xy() const;
266 constexpr GfVec2i xz() const;
267 constexpr GfVec2i yx() const;
268 constexpr GfVec2i yz() const;
269 constexpr GfVec2i zx() const;
270 constexpr GfVec2i zy() const;
271 constexpr GfVec3i xyz() const;
272 constexpr GfVec3i xzy() const;
273 constexpr GfVec3i yxz() const;
274 constexpr GfVec3i yzx() const;
275 constexpr GfVec3i zxy() const;
276 constexpr GfVec3i zyx() const;
278#else // !doxygen
279 // Note that these are templated on their own return type so that the
280 // declarations cost nothing in compile time & debug info unless they are
281 // actually called in a TU. Naming a different type is an error and
282 // static_assert()ed against.
283 template <class Vec = GfVec2i> constexpr Vec xy() const;
284 template <class Vec = GfVec2i> constexpr Vec xz() const;
285 template <class Vec = GfVec2i> constexpr Vec yx() const;
286 template <class Vec = GfVec2i> constexpr Vec yz() const;
287 template <class Vec = GfVec2i> constexpr Vec zx() const;
288 template <class Vec = GfVec2i> constexpr Vec zy() const;
289 template <class Vec = GfVec3i> constexpr Vec xyz() const;
290 template <class Vec = GfVec3i> constexpr Vec xzy() const;
291 template <class Vec = GfVec3i> constexpr Vec yxz() const;
292 template <class Vec = GfVec3i> constexpr Vec yzx() const;
293 template <class Vec = GfVec3i> constexpr Vec zxy() const;
294 template <class Vec = GfVec3i> constexpr Vec zyx() const;
295#endif // doxygen
296 };
297
300GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
301
302PXR_NAMESPACE_CLOSE_SCOPE
303
304// Lower dimensions of the same scalar type, for the swizzles above. Note that
305// lower dimensions never include higher ones, so this introduces no cycle.
306#include "pxr/base/gf/vec2i.h"
307
308PXR_NAMESPACE_OPEN_SCOPE
309
310
311template <class Vec>
312constexpr Vec
313GfVec3i::xy() const
314{
315 static_assert(std::is_same<Vec, GfVec2i>::value);
316 return Vec(x, y);
317}
318
319template <class Vec>
320constexpr Vec
321GfVec3i::xz() const
322{
323 static_assert(std::is_same<Vec, GfVec2i>::value);
324 return Vec(x, z);
325}
326
327template <class Vec>
328constexpr Vec
329GfVec3i::yx() const
330{
331 static_assert(std::is_same<Vec, GfVec2i>::value);
332 return Vec(y, x);
333}
334
335template <class Vec>
336constexpr Vec
337GfVec3i::yz() const
338{
339 static_assert(std::is_same<Vec, GfVec2i>::value);
340 return Vec(y, z);
341}
342
343template <class Vec>
344constexpr Vec
345GfVec3i::zx() const
346{
347 static_assert(std::is_same<Vec, GfVec2i>::value);
348 return Vec(z, x);
349}
350
351template <class Vec>
352constexpr Vec
353GfVec3i::zy() const
354{
355 static_assert(std::is_same<Vec, GfVec2i>::value);
356 return Vec(z, y);
357}
358
359template <class Vec>
360constexpr Vec
361GfVec3i::xyz() const
362{
363 static_assert(std::is_same<Vec, GfVec3i>::value);
364 return Vec(x, y, z);
365}
366
367template <class Vec>
368constexpr Vec
369GfVec3i::xzy() const
370{
371 static_assert(std::is_same<Vec, GfVec3i>::value);
372 return Vec(x, z, y);
373}
374
375template <class Vec>
376constexpr Vec
377GfVec3i::yxz() const
378{
379 static_assert(std::is_same<Vec, GfVec3i>::value);
380 return Vec(y, x, z);
381}
382
383template <class Vec>
384constexpr Vec
385GfVec3i::yzx() const
386{
387 static_assert(std::is_same<Vec, GfVec3i>::value);
388 return Vec(y, z, x);
389}
390
391template <class Vec>
392constexpr Vec
393GfVec3i::zxy() const
394{
395 static_assert(std::is_same<Vec, GfVec3i>::value);
396 return Vec(z, x, y);
397}
398
399template <class Vec>
400constexpr Vec
401GfVec3i::zyx() const
402{
403 static_assert(std::is_same<Vec, GfVec3i>::value);
404 return Vec(z, y, x);
405}
406
407
409inline GfVec3i
410GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
411 return GfVec3i(
412 v1.x * v2.x,
413 v1.y * v2.y,
414 v1.z * v2.z
415 );
416}
417
419inline GfVec3i
420GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
421 return GfVec3i(
422 v1.x / v2.x,
423 v1.y / v2.y,
424 v1.z / v2.z
425 );
426}
427
429inline int
430GfDot(GfVec3i const &v1, GfVec3i const &v2) {
431 return v1 * v2;
432}
433
434
435PXR_NAMESPACE_CLOSE_SCOPE
436
437#endif // PXR_BASE_GF_VEC3I_H
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 int components.
Definition vec2i.h:44
Basic type for a vector of 3 double components.
Definition vec3d.h:47
Basic type for a vector of 3 float components.
Definition vec3f.h:47
Basic type for a vector of 3 GfHalf components.
Definition vec3h.h:48
Basic type for a vector of 3 int components.
Definition vec3i.h:45
int ScalarType
Scalar element type and dimension.
Definition vec3i.h:48
GF_API bool operator==(class GfVec3h const &other) const
Equality comparison.
int operator*(GfVec3i const &v) const
See GfDot().
Definition vec3i.h:222
GfVec3i()=default
GfVec3i value-initializes to zero and performs no default initialization, like float or double.
GfVec3i & operator/=(int s)
Division by scalar.
Definition vec3i.h:211
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition vec3i.h:186
GF_API bool operator==(class GfVec3d const &other) const
Equality comparison.
GF_API bool operator==(class GfVec3f const &other) const
Equality comparison.
constexpr GfVec3i(int value)
Initialize all elements to a single value.
Definition vec3i.h:70
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition vec3i.h:118
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition vec3i.h:102
GfVec3i GetComplement(GfVec3i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition vec3i.h:239
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition vec3i.h:144
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition vec3i.h:88
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition vec3i.h:149
int const * data() const
Direct data access.
Definition vec3i.h:135
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition vec3i.h:83
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition vec3i.h:95
static GfVec3i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition vec3i.h:110
GfVec3i GetProjection(GfVec3i const &v) const
Returns the projection of this onto v.
Definition vec3i.h:230
int const & operator[](size_t i) const
Indexing.
Definition vec3i.h:140
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition vec3i.h:76
GfVec3i operator-() const
Create a vec with negated elements.
Definition vec3i.h:170
int GetLengthSq() const
Squared length.
Definition vec3i.h:244
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition vec3i.h:175
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition vec3i.h:126
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition vec3i.h:197
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition hash.h:487
GF_API std::ostream & operator<<(std::ostream &, GfVec3i const &)
Output a GfVec3i.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
Definition traits.h:23
GfVec3i GfCompMult(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition vec3i.h:410
GfVec3i GfCompDiv(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition vec3i.h:420
int GfDot(GfVec3i const &v1, GfVec3i const &v2)
Returns the dot (inner) product of two vectors.
Definition vec3i.h:430