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"
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
28PXR_NAMESPACE_OPEN_SCOPE
29
30class GfVec3i;
31
32template <>
33struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
34
44{
45public:
47 typedef int ScalarType;
48 static const size_t dimension = 3;
49
52 GfVec3i() = default;
53
55 constexpr explicit GfVec3i(int value)
56 : _data{ value, value, value }
57 {
58 }
59
61 constexpr GfVec3i(int s0, int s1, int s2)
62 : _data{ s0, s1, s2 }
63 {
64 }
65
67 template <class Scl>
68 constexpr explicit GfVec3i(Scl const *p)
69 : _data{ p[0], p[1], p[2] }
70 {
71 }
72
74 static GfVec3i XAxis() {
75 GfVec3i result(0);
76 result[0] = 1;
77 return result;
78 }
80 static GfVec3i YAxis() {
81 GfVec3i result(0);
82 result[1] = 1;
83 return result;
84 }
86 static GfVec3i ZAxis() {
87 GfVec3i result(0);
88 result[2] = 1;
89 return result;
90 }
91
94 static GfVec3i Axis(size_t i) {
95 GfVec3i result(0);
96 if (i < 3)
97 result[i] = 1;
98 return result;
99 }
100
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
110 GfVec3i &Set(int const *a) {
111 return Set(a[0], a[1], a[2]);
112 }
113
115 int const *data() const { return _data; }
116 int *data() { return _data; }
117 int const *GetArray() const { return data(); }
118
120 int const &operator[](size_t i) const { return _data[i]; }
121 int &operator[](size_t i) { return _data[i]; }
122
124 friend inline size_t hash_value(GfVec3i const &vec) {
125 return TfHash::Combine(vec[0], vec[1], vec[2]);
126 }
127
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...
140 GF_API
141 bool operator==(class GfVec3d const &other) const;
143 GF_API
144 bool operator==(class GfVec3f const &other) const;
146 GF_API
147 bool operator==(class GfVec3h const &other) const;
148
151 return GfVec3i(-_data[0], -_data[1], -_data[2]);
152 }
153
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
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
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
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
202 int operator*(GfVec3i const &v) const {
203 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
204 }
205
210 GfVec3i GetProjection(GfVec3i const &v) const {
211 return v * (*this * v);
212 }
213
219 GfVec3i GetComplement(GfVec3i const &b) const {
220 return *this - this->GetProjection(b);
221 }
222
224 int GetLengthSq() const {
225 return *this * *this;
226 }
227
228
229private:
230 int _data[3];
231};
232
235GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
236
237
239inline GfVec3i
240GfCompMult(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
249inline GfVec3i
250GfCompDiv(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
259inline int
260GfDot(GfVec3i const &v1, GfVec3i const &v2) {
261 return v1 * v2;
262}
263
264
265PXR_NAMESPACE_CLOSE_SCOPE
266
267#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 3 double components.
Definition: vec3d.h:46
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:47
Basic type for a vector of 3 int components.
Definition: vec3i.h:44
GF_API bool operator==(class GfVec3h const &other) const
Equality comparison.
int operator*(GfVec3i const &v) const
See GfDot().
Definition: vec3i.h:202
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:191
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition: vec3i.h:166
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:55
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition: vec3i.h:102
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec3i.h:86
GfVec3i GetComplement(GfVec3i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec3i.h:219
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition: vec3i.h:124
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition: vec3i.h:74
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition: vec3i.h:129
int const * data() const
Direct data access.
Definition: vec3i.h:115
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition: vec3i.h:68
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition: vec3i.h:80
static GfVec3i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec3i.h:94
GfVec3i GetProjection(GfVec3i const &v) const
Returns the projection of this onto v.
Definition: vec3i.h:210
int const & operator[](size_t i) const
Indexing.
Definition: vec3i.h:120
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition: vec3i.h:61
GfVec3i operator-() const
Create a vec with negated elements.
Definition: vec3i.h:150
int ScalarType
Scalar element type and dimension.
Definition: vec3i.h:47
int GetLengthSq() const
Squared length.
Definition: vec3i.h:224
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition: vec3i.h:155
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec3i.h:110
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition: vec3i.h:177
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 &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
Definition: traits.h:19
GfVec3i GfCompMult(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec3i.h:240
GfVec3i GfCompDiv(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec3i.h:250
int GfDot(GfVec3i const &v1, GfVec3i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec3i.h:260