All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
size3.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//
7#ifndef PXR_BASE_GF_SIZE3_H
8#define PXR_BASE_GF_SIZE3_H
9
12
13#include "pxr/pxr.h"
15#include "pxr/base/gf/vec3i.h"
16#include "pxr/base/gf/api.h"
17
18#include <iosfwd>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
34class GfSize3 {
35public:
38 Set(0, 0, 0);
39 }
40
42 GfSize3(const GfSize3& o) {
43 *this = o;
44 }
45
47 explicit GfSize3(const GfVec3i&o) {
48 Set(o[0], o[1], o[2]);
49 }
50
52 GfSize3(const size_t v[3]) {
53 Set(v);
54 }
55
57 GfSize3(size_t v0, size_t v1, size_t v2) {
58 Set(v0, v1, v2);
59 }
60
62 GfSize3 & Set(const size_t v[3]) {
63 _vec[0] = v[0];
64 _vec[1] = v[1];
65 _vec[2] = v[2];
66 return *this;
67 }
68
70 GfSize3 & Set(size_t v0, size_t v1, size_t v2) {
71 _vec[0] = v0;
72 _vec[1] = v1;
73 _vec[2] = v2;
74 return *this;
75 }
76
78 size_t & operator [](size_t i) {
79 return _vec[i];
80 }
81
83 const size_t & operator [](size_t i) const {
84 return _vec[i];
85 }
86
88 bool operator ==(const GfSize3 &v) const {
89 return _vec[0] == v._vec[0] && _vec[1] == v._vec[1] &&
90 _vec[2] == v._vec[2];
91 }
92
94 bool operator !=(const GfSize3 &v) const {
95 return ! (*this == v);
96 }
97
100 _vec[0] += v._vec[0];
101 _vec[1] += v._vec[1];
102 _vec[2] += v._vec[2];
103 return *this;
104 }
105
108 _vec[0] -= v._vec[0];
109 _vec[1] -= v._vec[1];
110 _vec[2] -= v._vec[2];
111 return *this;
112 }
113
116 _vec[0] *= v._vec[0];
117 _vec[1] *= v._vec[1];
118 _vec[2] *= v._vec[2];
119 return *this;
120 }
121
123 GfSize3 & operator *=(size_t d) {
124 _vec[0] = _vec[0] * d;
125 _vec[1] = _vec[1] * d;
126 _vec[2] = _vec[2] * d;
127 return *this;
128 }
129
131 GfSize3 & operator /=(size_t d) {
132 _vec[0] = _vec[0] / d;
133 _vec[1] = _vec[1] / d;
134 _vec[2] = _vec[2] / d;
135 return *this;
136 }
137
139 friend GfSize3 operator +(const GfSize3 &v1, const GfSize3 &v3) {
140 return GfSize3(v1._vec[0]+v3._vec[0],
141 v1._vec[1]+v3._vec[1],
142 v1._vec[2]+v3._vec[2]);
143 }
144
146 friend GfSize3 operator -(const GfSize3 &v1, const GfSize3 &v3) {
147 return GfSize3(v1._vec[0]-v3._vec[0],
148 v1._vec[1]-v3._vec[1],
149 v1._vec[2]-v3._vec[2]);
150 }
151
153 friend GfSize3 operator *(const GfSize3 &v1, const GfSize3 &v3) {
154 return GfSize3(v1._vec[0]*v3._vec[0],
155 v1._vec[1]*v3._vec[1],
156 v1._vec[2]*v3._vec[2]);
157 }
158
160 friend GfSize3 operator *(const GfSize3 &v1, size_t s) {
161 return GfSize3(v1._vec[0]*s,
162 v1._vec[1]*s,
163 v1._vec[2]*s);
164 }
165
167 friend GfSize3 operator *(size_t s, const GfSize3 &v1) {
168 return GfSize3(v1._vec[0]*s,
169 v1._vec[1]*s,
170 v1._vec[2]*s);
171 }
172
174 friend GfSize3 operator /(const GfSize3 &v1, size_t s) {
175 return GfSize3(v1._vec[0]/s,
176 v1._vec[1]/s,
177 v1._vec[2]/s);
178 }
179
181 friend GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
182
184 operator GfVec3i() const {
185 return GfVec3i(_vec[0],_vec[1],_vec[2]);
186 }
187private:
188 size_t _vec[3];
189};
190
191// Friend functions must be declared
192GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
193
194PXR_NAMESPACE_CLOSE_SCOPE
195
196#endif // PXR_BASE_GF_SIZE3_H
Three-dimensional array of sizes.
Definition: size3.h:34
GfSize3 & Set(const size_t v[3])
Set to the values in v.
Definition: size3.h:62
friend GF_API std::ostream & operator<<(std::ostream &o, GfSize3 const &v)
Output operator.
GfSize3()
Default constructor initializes components to zero.
Definition: size3.h:37
GfSize3(const GfSize3 &o)
Copy constructor.
Definition: size3.h:42
GfSize3 & operator/=(size_t d)
Component-wise in-place division by a scalar.
Definition: size3.h:131
friend GfSize3 operator/(const GfSize3 &v1, size_t s)
Component-wise division by a scalar.
Definition: size3.h:174
GfSize3(const GfVec3i &o)
Conversion from GfVec3i.
Definition: size3.h:47
bool operator==(const GfSize3 &v) const
Component-wise equality.
Definition: size3.h:88
GfSize3(size_t v0, size_t v1, size_t v2)
Construct from three values.
Definition: size3.h:57
friend GfSize3 operator+(const GfSize3 &v1, const GfSize3 &v3)
Component-wise addition.
Definition: size3.h:139
GfSize3 & operator-=(const GfSize3 &v)
Component-wise in-place subtraction.
Definition: size3.h:107
friend GfSize3 operator-(const GfSize3 &v1, const GfSize3 &v3)
Component-wise subtraction.
Definition: size3.h:146
GfSize3(const size_t v[3])
Construct from an array.
Definition: size3.h:52
GfSize3 & operator*=(GfSize3 const &v)
Component-wise in-place multiplication.
Definition: size3.h:115
friend GfSize3 operator*(const GfSize3 &v1, const GfSize3 &v3)
Component-wise multiplication.
Definition: size3.h:153
GfSize3 & operator+=(const GfSize3 &v)
Component-wise in-place addition.
Definition: size3.h:99
GfSize3 & Set(size_t v0, size_t v1, size_t v2)
Set to values passed directly.
Definition: size3.h:70
size_t & operator[](size_t i)
Array operator.
Definition: size3.h:78
bool operator!=(const GfSize3 &v) const
Component-wise inequality.
Definition: size3.h:94
Basic type for a vector of 3 int components.
Definition: vec3i.h:44
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Define integral types.