All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
size3.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 //
24 #ifndef GF_SIZE3_H
25 #define GF_SIZE3_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/arch/inttypes.h"
32 #include "pxr/base/gf/vec3i.h"
33 #include "pxr/base/gf/api.h"
34 
35 #include <iosfwd>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
51 class GfSize3 {
52 public:
54  GfSize3() {
55  Set(0, 0, 0);
56  }
57 
59  GfSize3(const GfSize3& o) {
60  *this = o;
61  }
62 
64  explicit GfSize3(const GfVec3i&o) {
65  Set(o[0], o[1], o[2]);
66  }
67 
69  GfSize3(const size_t v[3]) {
70  Set(v);
71  }
72 
74  GfSize3(size_t v0, size_t v1, size_t v2) {
75  Set(v0, v1, v2);
76  }
77 
79  GfSize3 & Set(const size_t v[3]) {
80  _vec[0] = v[0];
81  _vec[1] = v[1];
82  _vec[2] = v[2];
83  return *this;
84  }
85 
87  GfSize3 & Set(size_t v0, size_t v1, size_t v2) {
88  _vec[0] = v0;
89  _vec[1] = v1;
90  _vec[2] = v2;
91  return *this;
92  }
93 
95  size_t & operator [](size_t i) {
96  return _vec[i];
97  }
98 
100  const size_t & operator [](size_t i) const {
101  return _vec[i];
102  }
103 
105  bool operator ==(const GfSize3 &v) const {
106  return _vec[0] == v._vec[0] && _vec[1] == v._vec[1] &&
107  _vec[2] == v._vec[2];
108  }
109 
111  bool operator !=(const GfSize3 &v) const {
112  return ! (*this == v);
113  }
114 
117  _vec[0] += v._vec[0];
118  _vec[1] += v._vec[1];
119  _vec[2] += v._vec[2];
120  return *this;
121  }
122 
125  _vec[0] -= v._vec[0];
126  _vec[1] -= v._vec[1];
127  _vec[2] -= v._vec[2];
128  return *this;
129  }
130 
133  _vec[0] *= v._vec[0];
134  _vec[1] *= v._vec[1];
135  _vec[2] *= v._vec[2];
136  return *this;
137  }
138 
140  GfSize3 & operator *=(size_t d) {
141  _vec[0] = _vec[0] * d;
142  _vec[1] = _vec[1] * d;
143  _vec[2] = _vec[2] * d;
144  return *this;
145  }
146 
148  GfSize3 & operator /=(size_t d) {
149  _vec[0] = _vec[0] / d;
150  _vec[1] = _vec[1] / d;
151  _vec[2] = _vec[2] / d;
152  return *this;
153  }
154 
156  friend GfSize3 operator +(const GfSize3 &v1, const GfSize3 &v3) {
157  return GfSize3(v1._vec[0]+v3._vec[0],
158  v1._vec[1]+v3._vec[1],
159  v1._vec[2]+v3._vec[2]);
160  }
161 
163  friend GfSize3 operator -(const GfSize3 &v1, const GfSize3 &v3) {
164  return GfSize3(v1._vec[0]-v3._vec[0],
165  v1._vec[1]-v3._vec[1],
166  v1._vec[2]-v3._vec[2]);
167  }
168 
170  friend GfSize3 operator *(const GfSize3 &v1, const GfSize3 &v3) {
171  return GfSize3(v1._vec[0]*v3._vec[0],
172  v1._vec[1]*v3._vec[1],
173  v1._vec[2]*v3._vec[2]);
174  }
175 
177  friend GfSize3 operator *(const GfSize3 &v1, size_t s) {
178  return GfSize3(v1._vec[0]*s,
179  v1._vec[1]*s,
180  v1._vec[2]*s);
181  }
182 
184  friend GfSize3 operator *(size_t s, const GfSize3 &v1) {
185  return GfSize3(v1._vec[0]*s,
186  v1._vec[1]*s,
187  v1._vec[2]*s);
188  }
189 
191  friend GfSize3 operator /(const GfSize3 &v1, size_t s) {
192  return GfSize3(v1._vec[0]/s,
193  v1._vec[1]/s,
194  v1._vec[2]/s);
195  }
196 
198  friend GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
199 
201  operator GfVec3i() const {
202  return GfVec3i(_vec[0],_vec[1],_vec[2]);
203  }
204 private:
205  size_t _vec[3];
206 };
207 
208 // Friend functions must be declared
209 GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
210 
211 PXR_NAMESPACE_CLOSE_SCOPE
212 
213 #endif // GF_SIZE3_H
GfSize3()
Default constructor initializes components to zero.
Definition: size3.h:54
friend GfSize3 operator*(const GfSize3 &v1, const GfSize3 &v3)
Component-wise multiplication.
Definition: size3.h:170
Three-dimensional array of sizes.
Definition: size3.h:51
GfSize3 & Set(const size_t v[3])
Set to the values in v.
Definition: size3.h:79
GfSize3 & Set(size_t v0, size_t v1, size_t v2)
Set to values passed directly.
Definition: size3.h:87
friend GF_API std::ostream & operator<<(std::ostream &o, GfSize3 const &v)
Output operator.
GfSize3(const GfVec3i &o)
Conversion from GfVec3i.
Definition: size3.h:64
GfSize3 & operator/=(size_t d)
Component-wise in-place division by a scalar.
Definition: size3.h:148
GfSize3 & operator+=(const GfSize3 &v)
Component-wise in-place addition.
Definition: size3.h:116
friend GfSize3 operator/(const GfSize3 &v1, size_t s)
Component-wise division by a scalar.
Definition: size3.h:191
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
GfSize3(const GfSize3 &o)
Copy constructor.
Definition: size3.h:59
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
bool operator==(const GfSize3 &v) const
Component-wise equality.
Definition: size3.h:105
friend GfSize3 operator-(const GfSize3 &v1, const GfSize3 &v3)
Component-wise subtraction.
Definition: size3.h:163
GfSize3(const size_t v[3])
Construct from an array.
Definition: size3.h:69
GfSize3 & operator*=(GfSize3 const &v)
Component-wise in-place multiplication.
Definition: size3.h:132
size_t & operator[](size_t i)
Array operator.
Definition: size3.h:95
friend GfSize3 operator+(const GfSize3 &v1, const GfSize3 &v3)
Component-wise addition.
Definition: size3.h:156
GfSize3 & operator-=(const GfSize3 &v)
Component-wise in-place subtraction.
Definition: size3.h:124
GfSize3(size_t v0, size_t v1, size_t v2)
Construct from three values.
Definition: size3.h:74
bool operator!=(const GfSize3 &v) const
Component-wise inequality.
Definition: size3.h:111