All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
51 GfVec3i() = default;
52
54 constexpr explicit GfVec3i(int value)
55 : _data{ value, value, value }
56 {
57 }
58
60 constexpr GfVec3i(int s0, int s1, int s2)
61 : _data{ s0, s1, s2 }
62 {
63 }
64
66 template <class Scl>
67 constexpr explicit GfVec3i(Scl const *p)
68 : _data{ p[0], p[1], p[2] }
69 {
70 }
71
73 static GfVec3i XAxis() {
74 GfVec3i result(0);
75 result[0] = 1;
76 return result;
77 }
79 static GfVec3i YAxis() {
80 GfVec3i result(0);
81 result[1] = 1;
82 return result;
83 }
85 static GfVec3i ZAxis() {
86 GfVec3i result(0);
87 result[2] = 1;
88 return result;
89 }
90
93 static GfVec3i Axis(size_t i) {
94 GfVec3i result(0);
95 if (i < 3)
96 result[i] = 1;
97 return result;
98 }
99
101 GfVec3i &Set(int s0, int s1, int s2) {
102 _data[0] = s0;
103 _data[1] = s1;
104 _data[2] = s2;
105 return *this;
106 }
107
109 GfVec3i &Set(int const *a) {
110 return Set(a[0], a[1], a[2]);
111 }
112
114 int const *data() const { return _data; }
115 int *data() { return _data; }
116 int const *GetArray() const { return data(); }
117
119 int const &operator[](size_t i) const { return _data[i]; }
120 int &operator[](size_t i) { return _data[i]; }
121
123 friend inline size_t hash_value(GfVec3i const &vec) {
124 return TfHash::Combine(vec[0], vec[1], vec[2]);
125 }
126
128 bool operator==(GfVec3i const &other) const {
129 return _data[0] == other[0] &&
130 _data[1] == other[1] &&
131 _data[2] == other[2];
132 }
133 bool operator!=(GfVec3i const &other) const {
134 return !(*this == other);
135 }
136
137 // TODO Add inequality for other vec types...
139 GF_API
140 bool operator==(class GfVec3d const &other) const;
142 GF_API
143 bool operator==(class GfVec3f const &other) const;
145 GF_API
146 bool operator==(class GfVec3h const &other) const;
147
150 return GfVec3i(-_data[0], -_data[1], -_data[2]);
151 }
152
154 GfVec3i &operator+=(GfVec3i const &other) {
155 _data[0] += other[0];
156 _data[1] += other[1];
157 _data[2] += other[2];
158 return *this;
159 }
160 friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
161 return GfVec3i(l) += r;
162 }
163
165 GfVec3i &operator-=(GfVec3i const &other) {
166 _data[0] -= other[0];
167 _data[1] -= other[1];
168 _data[2] -= other[2];
169 return *this;
170 }
171 friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
172 return GfVec3i(l) -= r;
173 }
174
176 GfVec3i &operator*=(double s) {
177 _data[0] *= s;
178 _data[1] *= s;
179 _data[2] *= s;
180 return *this;
181 }
182 GfVec3i operator*(double s) const {
183 return GfVec3i(*this) *= s;
184 }
185 friend GfVec3i operator*(double s, GfVec3i const &v) {
186 return v * s;
187 }
188
191 _data[0] /= s;
192 _data[1] /= s;
193 _data[2] /= s;
194 return *this;
195 }
196 GfVec3i operator/(int s) const {
197 return GfVec3i(*this) /= s;
198 }
199
201 int operator*(GfVec3i const &v) const {
202 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
203 }
204
209 GfVec3i GetProjection(GfVec3i const &v) const {
210 return v * (*this * v);
211 }
212
218 GfVec3i GetComplement(GfVec3i const &b) const {
219 return *this - this->GetProjection(b);
220 }
221
223 int GetLengthSq() const {
224 return *this * *this;
225 }
226
227
228private:
229 int _data[3];
230};
231
234GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
235
236
238inline GfVec3i
239GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
240 return GfVec3i(
241 v1[0] * v2[0],
242 v1[1] * v2[1],
243 v1[2] * v2[2]
244 );
245}
246
248inline GfVec3i
249GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
250 return GfVec3i(
251 v1[0] / v2[0],
252 v1[1] / v2[1],
253 v1[2] / v2[2]
254 );
255}
256
258inline int
259GfDot(GfVec3i const &v1, GfVec3i const &v2) {
260 return v1 * v2;
261}
262
263
264PXR_NAMESPACE_CLOSE_SCOPE
265
266#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:201
GfVec3i()=default
Default constructor does no initialization.
GfVec3i & operator/=(int s)
Division by scalar.
Definition: vec3i.h:190
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition: vec3i.h:165
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:54
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition: vec3i.h:101
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec3i.h:85
GfVec3i GetComplement(GfVec3i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec3i.h:218
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition: vec3i.h:123
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition: vec3i.h:73
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition: vec3i.h:128
int const * data() const
Direct data access.
Definition: vec3i.h:114
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition: vec3i.h:67
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition: vec3i.h:79
static GfVec3i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec3i.h:93
GfVec3i GetProjection(GfVec3i const &v) const
Returns the projection of this onto v.
Definition: vec3i.h:209
int const & operator[](size_t i) const
Indexing.
Definition: vec3i.h:119
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition: vec3i.h:60
GfVec3i operator-() const
Create a vec with negated elements.
Definition: vec3i.h:149
int ScalarType
Scalar element type and dimension.
Definition: vec3i.h:47
int GetLengthSq() const
Squared length.
Definition: vec3i.h:223
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition: vec3i.h:154
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec3i.h:109
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition: vec3i.h:176
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:475
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:239
GfVec3i GfCompDiv(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec3i.h:249
int GfDot(GfVec3i const &v1, GfVec3i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec3i.h:259