Loading...
Searching...
No Matches
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//
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
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 GfVec4i;
31
32template <>
33struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
34
44{
45public:
47 typedef int ScalarType;
48 static const size_t dimension = 4;
49
51 GfVec4i() = default;
52
54 constexpr explicit GfVec4i(int value)
55 : _data{ value, value, value, value }
56 {
57 }
58
60 constexpr GfVec4i(int s0, int s1, int s2, int s3)
61 : _data{ s0, s1, s2, s3 }
62 {
63 }
64
66 template <class Scl>
67 constexpr explicit GfVec4i(Scl const *p)
68 : _data{ p[0], p[1], p[2], p[3] }
69 {
70 }
71
73 static GfVec4i XAxis() {
74 GfVec4i result(0);
75 result[0] = 1;
76 return result;
77 }
79 static GfVec4i YAxis() {
80 GfVec4i result(0);
81 result[1] = 1;
82 return result;
83 }
85 static GfVec4i ZAxis() {
86 GfVec4i result(0);
87 result[2] = 1;
88 return result;
89 }
91 static GfVec4i WAxis() {
92 GfVec4i result(0);
93 result[3] = 1;
94 return result;
95 }
96
99 static GfVec4i Axis(size_t i) {
100 GfVec4i result(0);
101 if (i < 4)
102 result[i] = 1;
103 return result;
104 }
105
107 GfVec4i &Set(int s0, int s1, int s2, int s3) {
108 _data[0] = s0;
109 _data[1] = s1;
110 _data[2] = s2;
111 _data[3] = s3;
112 return *this;
113 }
114
116 GfVec4i &Set(int const *a) {
117 return Set(a[0], a[1], a[2], a[3]);
118 }
119
121 int const *data() const { return _data; }
122 int *data() { return _data; }
123 int const *GetArray() const { return data(); }
124
126 int const &operator[](size_t i) const { return _data[i]; }
127 int &operator[](size_t i) { return _data[i]; }
128
130 friend inline size_t hash_value(GfVec4i const &vec) {
131 return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]);
132 }
133
135 bool operator==(GfVec4i const &other) const {
136 return _data[0] == other[0] &&
137 _data[1] == other[1] &&
138 _data[2] == other[2] &&
139 _data[3] == other[3];
140 }
141 bool operator!=(GfVec4i const &other) const {
142 return !(*this == other);
143 }
144
145 // TODO Add inequality for other vec types...
147 GF_API
148 bool operator==(class GfVec4d const &other) const;
150 GF_API
151 bool operator==(class GfVec4f const &other) const;
153 GF_API
154 bool operator==(class GfVec4h const &other) const;
155
158 return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
159 }
160
162 GfVec4i &operator+=(GfVec4i const &other) {
163 _data[0] += other[0];
164 _data[1] += other[1];
165 _data[2] += other[2];
166 _data[3] += other[3];
167 return *this;
168 }
169 friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
170 return GfVec4i(l) += r;
171 }
172
174 GfVec4i &operator-=(GfVec4i const &other) {
175 _data[0] -= other[0];
176 _data[1] -= other[1];
177 _data[2] -= other[2];
178 _data[3] -= other[3];
179 return *this;
180 }
181 friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
182 return GfVec4i(l) -= r;
183 }
184
186 GfVec4i &operator*=(double s) {
187 _data[0] *= s;
188 _data[1] *= s;
189 _data[2] *= s;
190 _data[3] *= s;
191 return *this;
192 }
193 GfVec4i operator*(double s) const {
194 return GfVec4i(*this) *= s;
195 }
196 friend GfVec4i operator*(double s, GfVec4i const &v) {
197 return v * s;
198 }
199
202 _data[0] /= s;
203 _data[1] /= s;
204 _data[2] /= s;
205 _data[3] /= s;
206 return *this;
207 }
208 GfVec4i operator/(int s) const {
209 return GfVec4i(*this) /= s;
210 }
211
213 int operator*(GfVec4i const &v) const {
214 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
215 }
216
221 GfVec4i GetProjection(GfVec4i const &v) const {
222 return v * (*this * v);
223 }
224
230 GfVec4i GetComplement(GfVec4i const &b) const {
231 return *this - this->GetProjection(b);
232 }
233
235 int GetLengthSq() const {
236 return *this * *this;
237 }
238
239
240private:
241 int _data[4];
242};
243
246GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
247
248
250inline GfVec4i
251GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
252 return GfVec4i(
253 v1[0] * v2[0],
254 v1[1] * v2[1],
255 v1[2] * v2[2],
256 v1[3] * v2[3]
257 );
258}
259
261inline GfVec4i
262GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
263 return GfVec4i(
264 v1[0] / v2[0],
265 v1[1] / v2[1],
266 v1[2] / v2[2],
267 v1[3] / v2[3]
268 );
269}
270
272inline int
273GfDot(GfVec4i const &v1, GfVec4i const &v2) {
274 return v1 * v2;
275}
276
277
278PXR_NAMESPACE_CLOSE_SCOPE
279
280#endif // PXR_BASE_GF_VEC4I_H
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 4 double components.
Definition: vec4d.h:46
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Basic type for a vector of 4 GfHalf components.
Definition: vec4h.h:47
Basic type for a vector of 4 int components.
Definition: vec4i.h:44
static GfVec4i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec4i.h:85
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:60
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:67
static GfVec4i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec4i.h:99
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:174
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:130
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:73
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:157
GfVec4i()=default
Default constructor does no initialization.
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:79
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:162
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:135
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:213
GfVec4i GetProjection(GfVec4i const &v) const
Returns the projection of this onto v.
Definition: vec4i.h:221
int const * data() const
Direct data access.
Definition: vec4i.h:121
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:126
GF_API bool operator==(class GfVec4h const &other) const
Equality comparison.
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:186
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:91
GfVec4i GetComplement(GfVec4i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec4i.h:230
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:107
GF_API bool operator==(class GfVec4d const &other) const
Equality comparison.
GfVec4i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec4i.h:116
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:47
int GetLengthSq() const
Squared length.
Definition: vec4i.h:235
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:54
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:201
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
GfVec4i GfCompMult(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec4i.h:251
int GfDot(GfVec4i const &v1, GfVec4i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec4i.h:273
GfVec4i GfCompDiv(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec4i.h:262