All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
size2.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 PXR_BASE_GF_SIZE2_H
25 #define PXR_BASE_GF_SIZE2_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/arch/inttypes.h"
32 #include "pxr/base/gf/vec2i.h"
33 #include "pxr/base/gf/api.h"
34 
35 #include <iosfwd>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
51 class GfSize2 {
52 public:
54  GfSize2() {
55  Set(0, 0);
56  }
57 
59  GfSize2(const GfSize2& o) {
60  *this = o;
61  }
62 
64  explicit GfSize2(const GfVec2i&o) {
65  Set(o[0], o[1]);
66  }
67 
69  GfSize2(const size_t v[2]) {
70  Set(v);
71  }
72 
74  GfSize2(size_t v0, size_t v1) {
75  Set(v0, v1);
76  }
77 
79  GfSize2 & Set(const size_t v[2]) {
80  _vec[0] = v[0];
81  _vec[1] = v[1];
82  return *this;
83  }
84 
86  GfSize2 & Set(size_t v0, size_t v1) {
87  _vec[0] = v0;
88  _vec[1] = v1;
89  return *this;
90  }
91 
93  size_t & operator [](size_t i) {
94  return _vec[i];
95  }
96 
98  const size_t & operator [](size_t i) const {
99  return _vec[i];
100  }
101 
103  bool operator ==(const GfSize2 &v) const {
104  return _vec[0] == v._vec[0] && _vec[1] == v._vec[1];
105  }
106 
108  bool operator !=(const GfSize2 &v) const {
109  return ! (*this == v);
110  }
111 
114  _vec[0] += v._vec[0];
115  _vec[1] += v._vec[1];
116  return *this;
117  }
118 
121  _vec[0] -= v._vec[0];
122  _vec[1] -= v._vec[1];
123  return *this;
124  }
125 
128  _vec[0] *= v._vec[0];
129  _vec[1] *= v._vec[1];
130  return *this;
131  }
132 
134  GfSize2 & operator *=(int d) {
135  _vec[0] = _vec[0] * d;
136  _vec[1] = _vec[1] * d;
137  return *this;
138  }
139 
141  GfSize2 & operator /=(int d) {
142  _vec[0] = _vec[0] / d;
143  _vec[1] = _vec[1] / d;
144  return *this;
145  }
146 
148  friend GfSize2 operator +(const GfSize2 &v1, const GfSize2 &v2) {
149  return GfSize2(v1._vec[0]+v2._vec[0],
150  v1._vec[1]+v2._vec[1]);
151  }
152 
154  friend GfSize2 operator -(const GfSize2 &v1, const GfSize2 &v2) {
155  return GfSize2(v1._vec[0]-v2._vec[0],
156  v1._vec[1]-v2._vec[1]);
157  }
158 
160  friend GfSize2 operator *(const GfSize2 &v1, const GfSize2 &v2) {
161  return GfSize2(v1._vec[0]*v2._vec[0],
162  v1._vec[1]*v2._vec[1]);
163  }
164 
166  friend GfSize2 operator *(const GfSize2 &v1, int s) {
167  return GfSize2(v1._vec[0]*s,
168  v1._vec[1]*s);
169  }
170 
172  friend GfSize2 operator *(int s, const GfSize2 &v1) {
173  return GfSize2(v1._vec[0]*s,
174  v1._vec[1]*s);
175  }
176 
178  friend GfSize2 operator /(const GfSize2 &v1, int s) {
179  return GfSize2(v1._vec[0]/s,
180  v1._vec[1]/s);
181  }
182 
184  GF_API
185  friend std::ostream &operator<<(std::ostream &o, GfSize2 const &v);
186 
188  operator GfVec2i() const {
189  return GfVec2i(_vec[0], _vec[1]);
190  }
191  private:
192  size_t _vec[2];
193 };
194 
195 // Friend functions must be declared
196 GF_API std::ostream &operator<<(std::ostream &o, GfSize2 const &v);
197 
198 PXR_NAMESPACE_CLOSE_SCOPE
199 
200 #endif // PXR_BASE_GF_SIZE2_H
GfSize2(size_t v0, size_t v1)
Construct from two values.
Definition: size2.h:74
size_t & operator[](size_t i)
Array operator.
Definition: size2.h:93
bool operator!=(const GfSize2 &v) const
Component-wise inequality.
Definition: size2.h:108
GfSize2(const GfVec2i &o)
Conversion from GfVec2i.
Definition: size2.h:64
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
GfSize2(const GfSize2 &o)
Copy constructor.
Definition: size2.h:59
GfSize2 & operator*=(GfSize2 const &v)
Component-wise in-place multiplication.
Definition: size2.h:127
GfSize2 & Set(const size_t v[2])
Set to the values in a given array.
Definition: size2.h:79
GfSize2()
Default constructor initializes components to zero.
Definition: size2.h:54
GfSize2(const size_t v[2])
Construct from an array.
Definition: size2.h:69
friend GfSize2 operator*(const GfSize2 &v1, const GfSize2 &v2)
Component-wise multiplication.
Definition: size2.h:160
friend GfSize2 operator/(const GfSize2 &v1, int s)
Component-wise division by a scalar.
Definition: size2.h:178
friend GfSize2 operator-(const GfSize2 &v1, const GfSize2 &v2)
Component-wise subtraction.
Definition: size2.h:154
Define integral types.
GfSize2 & Set(size_t v0, size_t v1)
Set to values passed directly.
Definition: size2.h:86
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GF_API friend std::ostream & operator<<(std::ostream &o, GfSize2 const &v)
Output operator.
Two-dimensional array of sizes.
Definition: size2.h:51
friend GfSize2 operator+(const GfSize2 &v1, const GfSize2 &v2)
Component-wise addition.
Definition: size2.h:148
GfSize2 & operator/=(int d)
Component-wise in-place division by a scalar.
Definition: size2.h:141
GfSize2 & operator+=(const GfSize2 &v)
Component-wise in-place addition.
Definition: size2.h:113
GfSize2 & operator-=(const GfSize2 &v)
Component-wise in-place subtraction.
Definition: size2.h:120
bool operator==(const GfSize2 &v) const
Component-wise equality.
Definition: size2.h:103