Loading...
Searching...
No Matches
vec4i.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
25// This file is generated by a script. Do not edit directly. Edit the
26// vec.template.h file to make changes.
27
28#ifndef PXR_BASE_GF_VEC4I_H
29#define PXR_BASE_GF_VEC4I_H
30
33
34#include "pxr/pxr.h"
36#include "pxr/base/gf/api.h"
37#include "pxr/base/gf/limits.h"
38#include "pxr/base/gf/traits.h"
39#include "pxr/base/tf/hash.h"
40
41#include <cstddef>
42
43#include <iosfwd>
44
45PXR_NAMESPACE_OPEN_SCOPE
46
47class GfVec4i;
48
49template <>
50struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
51
61{
62public:
64 typedef int ScalarType;
65 static const size_t dimension = 4;
66
68 GfVec4i() = default;
69
71 constexpr explicit GfVec4i(int value)
72 : _data{ value, value, value, value }
73 {
74 }
75
77 constexpr GfVec4i(int s0, int s1, int s2, int s3)
78 : _data{ s0, s1, s2, s3 }
79 {
80 }
81
83 template <class Scl>
84 constexpr explicit GfVec4i(Scl const *p)
85 : _data{ p[0], p[1], p[2], p[3] }
86 {
87 }
88
90 static GfVec4i XAxis() {
91 GfVec4i result(0);
92 result[0] = 1;
93 return result;
94 }
96 static GfVec4i YAxis() {
97 GfVec4i result(0);
98 result[1] = 1;
99 return result;
100 }
102 static GfVec4i ZAxis() {
103 GfVec4i result(0);
104 result[2] = 1;
105 return result;
106 }
108 static GfVec4i WAxis() {
109 GfVec4i result(0);
110 result[3] = 1;
111 return result;
112 }
113
116 static GfVec4i Axis(size_t i) {
117 GfVec4i result(0);
118 if (i < 4)
119 result[i] = 1;
120 return result;
121 }
122
124 GfVec4i &Set(int s0, int s1, int s2, int s3) {
125 _data[0] = s0;
126 _data[1] = s1;
127 _data[2] = s2;
128 _data[3] = s3;
129 return *this;
130 }
131
133 GfVec4i &Set(int const *a) {
134 return Set(a[0], a[1], a[2], a[3]);
135 }
136
138 int const *data() const { return _data; }
139 int *data() { return _data; }
140 int const *GetArray() const { return data(); }
141
143 int const &operator[](size_t i) const { return _data[i]; }
144 int &operator[](size_t i) { return _data[i]; }
145
147 friend inline size_t hash_value(GfVec4i const &vec) {
148 return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]);
149 }
150
152 bool operator==(GfVec4i const &other) const {
153 return _data[0] == other[0] &&
154 _data[1] == other[1] &&
155 _data[2] == other[2] &&
156 _data[3] == other[3];
157 }
158 bool operator!=(GfVec4i const &other) const {
159 return !(*this == other);
160 }
161
162 // TODO Add inequality for other vec types...
164 GF_API
165 bool operator==(class GfVec4d const &other) const;
167 GF_API
168 bool operator==(class GfVec4f const &other) const;
170 GF_API
171 bool operator==(class GfVec4h const &other) const;
172
175 return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
176 }
177
179 GfVec4i &operator+=(GfVec4i const &other) {
180 _data[0] += other[0];
181 _data[1] += other[1];
182 _data[2] += other[2];
183 _data[3] += other[3];
184 return *this;
185 }
186 friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
187 return GfVec4i(l) += r;
188 }
189
191 GfVec4i &operator-=(GfVec4i const &other) {
192 _data[0] -= other[0];
193 _data[1] -= other[1];
194 _data[2] -= other[2];
195 _data[3] -= other[3];
196 return *this;
197 }
198 friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
199 return GfVec4i(l) -= r;
200 }
201
203 GfVec4i &operator*=(double s) {
204 _data[0] *= s;
205 _data[1] *= s;
206 _data[2] *= s;
207 _data[3] *= s;
208 return *this;
209 }
210 GfVec4i operator*(double s) const {
211 return GfVec4i(*this) *= s;
212 }
213 friend GfVec4i operator*(double s, GfVec4i const &v) {
214 return v * s;
215 }
216
219 _data[0] /= s;
220 _data[1] /= s;
221 _data[2] /= s;
222 _data[3] /= s;
223 return *this;
224 }
225 GfVec4i operator/(int s) const {
226 return GfVec4i(*this) /= s;
227 }
228
230 int operator*(GfVec4i const &v) const {
231 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
232 }
233
238 GfVec4i GetProjection(GfVec4i const &v) const {
239 return v * (*this * v);
240 }
241
247 GfVec4i GetComplement(GfVec4i const &b) const {
248 return *this - this->GetProjection(b);
249 }
250
252 int GetLengthSq() const {
253 return *this * *this;
254 }
255
256
257private:
258 int _data[4];
259};
260
263GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
264
265
267inline GfVec4i
268GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
269 return GfVec4i(
270 v1[0] * v2[0],
271 v1[1] * v2[1],
272 v1[2] * v2[2],
273 v1[3] * v2[3]
274 );
275}
276
278inline GfVec4i
279GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
280 return GfVec4i(
281 v1[0] / v2[0],
282 v1[1] / v2[1],
283 v1[2] / v2[2],
284 v1[3] / v2[3]
285 );
286}
287
289inline int
290GfDot(GfVec4i const &v1, GfVec4i const &v2) {
291 return v1 * v2;
292}
293
294
295PXR_NAMESPACE_CLOSE_SCOPE
296
297#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:63
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Basic type for a vector of 4 GfHalf components.
Definition: vec4h.h:64
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
static GfVec4i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec4i.h:102
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:77
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:84
static GfVec4i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec4i.h:116
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:191
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:147
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:90
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:174
GfVec4i()=default
Default constructor does no initialization.
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:96
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:179
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:152
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:230
GfVec4i GetProjection(GfVec4i const &v) const
Returns the projection of this onto v.
Definition: vec4i.h:238
int const * data() const
Direct data access.
Definition: vec4i.h:138
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:143
GF_API bool operator==(class GfVec4h const &other) const
Equality comparison.
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:203
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:108
GfVec4i GetComplement(GfVec4i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec4i.h:247
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:124
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:133
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:64
int GetLengthSq() const
Squared length.
Definition: vec4i.h:252
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:71
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:218
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
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:36
GfVec4i GfCompMult(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec4i.h:268
int GfDot(GfVec4i const &v1, GfVec4i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec4i.h:290
GfVec4i GfCompDiv(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec4i.h:279