Loading...
Searching...
No Matches
vec3i.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_VEC3I_H
29#define PXR_BASE_GF_VEC3I_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 GfVec3i;
48
49template <>
50struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
51
61{
62public:
64 typedef int ScalarType;
65 static const size_t dimension = 3;
66
68 GfVec3i() = default;
69
71 constexpr explicit GfVec3i(int value)
72 : _data{ value, value, value }
73 {
74 }
75
77 constexpr GfVec3i(int s0, int s1, int s2)
78 : _data{ s0, s1, s2 }
79 {
80 }
81
83 template <class Scl>
84 constexpr explicit GfVec3i(Scl const *p)
85 : _data{ p[0], p[1], p[2] }
86 {
87 }
88
90 static GfVec3i XAxis() {
91 GfVec3i result(0);
92 result[0] = 1;
93 return result;
94 }
96 static GfVec3i YAxis() {
97 GfVec3i result(0);
98 result[1] = 1;
99 return result;
100 }
102 static GfVec3i ZAxis() {
103 GfVec3i result(0);
104 result[2] = 1;
105 return result;
106 }
107
110 static GfVec3i Axis(size_t i) {
111 GfVec3i result(0);
112 if (i < 3)
113 result[i] = 1;
114 return result;
115 }
116
118 GfVec3i &Set(int s0, int s1, int s2) {
119 _data[0] = s0;
120 _data[1] = s1;
121 _data[2] = s2;
122 return *this;
123 }
124
126 GfVec3i &Set(int const *a) {
127 return Set(a[0], a[1], a[2]);
128 }
129
131 int const *data() const { return _data; }
132 int *data() { return _data; }
133 int const *GetArray() const { return data(); }
134
136 int const &operator[](size_t i) const { return _data[i]; }
137 int &operator[](size_t i) { return _data[i]; }
138
140 friend inline size_t hash_value(GfVec3i const &vec) {
141 return TfHash::Combine(vec[0], vec[1], vec[2]);
142 }
143
145 bool operator==(GfVec3i const &other) const {
146 return _data[0] == other[0] &&
147 _data[1] == other[1] &&
148 _data[2] == other[2];
149 }
150 bool operator!=(GfVec3i const &other) const {
151 return !(*this == other);
152 }
153
154 // TODO Add inequality for other vec types...
156 GF_API
157 bool operator==(class GfVec3d const &other) const;
159 GF_API
160 bool operator==(class GfVec3f const &other) const;
162 GF_API
163 bool operator==(class GfVec3h const &other) const;
164
167 return GfVec3i(-_data[0], -_data[1], -_data[2]);
168 }
169
171 GfVec3i &operator+=(GfVec3i const &other) {
172 _data[0] += other[0];
173 _data[1] += other[1];
174 _data[2] += other[2];
175 return *this;
176 }
177 friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
178 return GfVec3i(l) += r;
179 }
180
182 GfVec3i &operator-=(GfVec3i const &other) {
183 _data[0] -= other[0];
184 _data[1] -= other[1];
185 _data[2] -= other[2];
186 return *this;
187 }
188 friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
189 return GfVec3i(l) -= r;
190 }
191
193 GfVec3i &operator*=(double s) {
194 _data[0] *= s;
195 _data[1] *= s;
196 _data[2] *= s;
197 return *this;
198 }
199 GfVec3i operator*(double s) const {
200 return GfVec3i(*this) *= s;
201 }
202 friend GfVec3i operator*(double s, GfVec3i const &v) {
203 return v * s;
204 }
205
208 _data[0] /= s;
209 _data[1] /= s;
210 _data[2] /= s;
211 return *this;
212 }
213 GfVec3i operator/(int s) const {
214 return GfVec3i(*this) /= s;
215 }
216
218 int operator*(GfVec3i const &v) const {
219 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
220 }
221
226 GfVec3i GetProjection(GfVec3i const &v) const {
227 return v * (*this * v);
228 }
229
235 GfVec3i GetComplement(GfVec3i const &b) const {
236 return *this - this->GetProjection(b);
237 }
238
240 int GetLengthSq() const {
241 return *this * *this;
242 }
243
244
245private:
246 int _data[3];
247};
248
251GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
252
253
255inline GfVec3i
256GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
257 return GfVec3i(
258 v1[0] * v2[0],
259 v1[1] * v2[1],
260 v1[2] * v2[2]
261 );
262}
263
265inline GfVec3i
266GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
267 return GfVec3i(
268 v1[0] / v2[0],
269 v1[1] / v2[1],
270 v1[2] / v2[2]
271 );
272}
273
275inline int
276GfDot(GfVec3i const &v1, GfVec3i const &v2) {
277 return v1 * v2;
278}
279
280
281PXR_NAMESPACE_CLOSE_SCOPE
282
283#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:63
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:64
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
GF_API bool operator==(class GfVec3h const &other) const
Equality comparison.
int operator*(GfVec3i const &v) const
See GfDot().
Definition: vec3i.h:218
GfVec3i()=default
Default constructor does no initialization.
GfVec3i & operator/=(int s)
Division by scalar.
Definition: vec3i.h:207
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition: vec3i.h:182
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:71
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition: vec3i.h:118
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec3i.h:102
GfVec3i GetComplement(GfVec3i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec3i.h:235
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition: vec3i.h:140
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition: vec3i.h:90
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition: vec3i.h:145
int const * data() const
Direct data access.
Definition: vec3i.h:131
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition: vec3i.h:84
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition: vec3i.h:96
static GfVec3i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec3i.h:110
GfVec3i GetProjection(GfVec3i const &v) const
Returns the projection of this onto v.
Definition: vec3i.h:226
int const & operator[](size_t i) const
Indexing.
Definition: vec3i.h:136
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition: vec3i.h:77
GfVec3i operator-() const
Create a vec with negated elements.
Definition: vec3i.h:166
int ScalarType
Scalar element type and dimension.
Definition: vec3i.h:64
int GetLengthSq() const
Squared length.
Definition: vec3i.h:240
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition: vec3i.h:171
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec3i.h:126
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition: vec3i.h:193
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
GfVec3i GfCompMult(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec3i.h:256
GfVec3i GfCompDiv(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec3i.h:266
int GfDot(GfVec3i const &v1, GfVec3i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec3i.h:276