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
52 GfVec4i() = default;
53
55 constexpr explicit GfVec4i(int value)
56 : _data{ value, value, value, value }
57 {
58 }
59
61 constexpr GfVec4i(int s0, int s1, int s2, int s3)
62 : _data{ s0, s1, s2, s3 }
63 {
64 }
65
67 template <class Scl>
68 constexpr explicit GfVec4i(Scl const *p)
69 : _data{ p[0], p[1], p[2], p[3] }
70 {
71 }
72
74 static GfVec4i XAxis() {
75 GfVec4i result(0);
76 result[0] = 1;
77 return result;
78 }
80 static GfVec4i YAxis() {
81 GfVec4i result(0);
82 result[1] = 1;
83 return result;
84 }
86 static GfVec4i ZAxis() {
87 GfVec4i result(0);
88 result[2] = 1;
89 return result;
90 }
92 static GfVec4i WAxis() {
93 GfVec4i result(0);
94 result[3] = 1;
95 return result;
96 }
97
100 static GfVec4i Axis(size_t i) {
101 GfVec4i result(0);
102 if (i < 4)
103 result[i] = 1;
104 return result;
105 }
106
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
117 GfVec4i &Set(int const *a) {
118 return Set(a[0], a[1], a[2], a[3]);
119 }
120
122 int const *data() const { return _data; }
123 int *data() { return _data; }
124 int const *GetArray() const { return data(); }
125
127 int const &operator[](size_t i) const { return _data[i]; }
128 int &operator[](size_t i) { return _data[i]; }
129
131 friend inline size_t hash_value(GfVec4i const &vec) {
132 return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]);
133 }
134
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...
148 GF_API
149 bool operator==(class GfVec4d const &other) const;
151 GF_API
152 bool operator==(class GfVec4f const &other) const;
154 GF_API
155 bool operator==(class GfVec4h const &other) const;
156
159 return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
160 }
161
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
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
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
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
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
222 GfVec4i GetProjection(GfVec4i const &v) const {
223 return v * (*this * v);
224 }
225
231 GfVec4i GetComplement(GfVec4i const &b) const {
232 return *this - this->GetProjection(b);
233 }
234
236 int GetLengthSq() const {
237 return *this * *this;
238 }
239
240
241private:
242 int _data[4];
243};
244
247GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
248
249
251inline GfVec4i
252GfCompMult(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
262inline GfVec4i
263GfCompDiv(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
273inline int
274GfDot(GfVec4i const &v1, GfVec4i const &v2) {
275 return v1 * v2;
276}
277
278
279PXR_NAMESPACE_CLOSE_SCOPE
280
281#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:86
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:61
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:68
static GfVec4i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec4i.h:100
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:175
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:131
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:74
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:158
GfVec4i()=default
GfVec4i value-initializes to zero and performs no default initialization, like float or double.
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:80
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:163
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:136
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:214
GfVec4i GetProjection(GfVec4i const &v) const
Returns the projection of this onto v.
Definition: vec4i.h:222
int const * data() const
Direct data access.
Definition: vec4i.h:122
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:127
GF_API bool operator==(class GfVec4h const &other) const
Equality comparison.
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:187
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:92
GfVec4i GetComplement(GfVec4i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec4i.h:231
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:108
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:117
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:47
int GetLengthSq() const
Squared length.
Definition: vec4i.h:236
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:55
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:202
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:252
int GfDot(GfVec4i const &v1, GfVec4i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec4i.h:274
GfVec4i GfCompDiv(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec4i.h:263