1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef SIZE_H
17 #define SIZE_H
18
19 #include "utils/scalar.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
24 class SizeF;
25 typedef SizeF Size;
26
27 class SizeF {
28 public:
29 inline SizeF() noexcept;
30 inline SizeF(const SizeF& s) noexcept;
31 inline SizeF(scalar w, scalar h) noexcept;
32 inline ~SizeF() noexcept;
33
34 inline bool IsZero() const;
35 inline bool IsEmpty() const;
36
37 inline scalar Width() const;
38 inline scalar Height() const;
39
40 inline void SetWidth(scalar w);
41 inline void SetHeight(scalar h);
42
43 friend inline bool operator==(const SizeF& s1, const SizeF& s2);
44 friend inline bool operator!=(const SizeF& s1, const SizeF& s2);
45
46 private:
47 scalar width_;
48 scalar height_;
49 };
50
SizeF()51 inline SizeF::SizeF() noexcept : width_(0.0), height_(0.0) {}
52
SizeF(const SizeF & s)53 inline SizeF::SizeF(const SizeF& s) noexcept : width_(s.Width()), height_(s.Height()) {}
54
SizeF(scalar w,scalar h)55 inline SizeF::SizeF(scalar w, scalar h) noexcept : width_(w), height_(h) {}
56
~SizeF()57 inline SizeF::~SizeF() noexcept {}
58
IsZero()59 inline bool SizeF::IsZero() const
60 {
61 return width_ == 0 && height_ == 0;
62 }
63
IsEmpty()64 inline bool SizeF::IsEmpty() const
65 {
66 return width_ <= 0 || height_ <= 0;
67 }
68
Width()69 inline scalar SizeF::Width() const
70 {
71 return width_;
72 }
73
Height()74 inline scalar SizeF::Height() const
75 {
76 return height_;
77 }
78
SetWidth(scalar w)79 inline void SizeF::SetWidth(scalar w)
80 {
81 width_ = w;
82 }
83
SetHeight(scalar h)84 inline void SizeF::SetHeight(scalar h)
85 {
86 height_ = h;
87 }
88
89 inline bool operator==(const SizeF& s1, const SizeF& s2)
90 {
91 return s1.width_ == s2.width_ && s1.height_ == s2.height_;
92 }
93
94 inline bool operator!=(const SizeF& s1, const SizeF& s2)
95 {
96 return s1.width_ != s2.width_ || s1.height_ != s2.height_;
97 }
98
99 class SizeI {
100 public:
101 inline SizeI() noexcept;
102 inline SizeI(const SizeI& s) noexcept;
103 inline SizeI(int w, int h) noexcept;
104 inline ~SizeI() noexcept;
105
106 inline bool IsZero() const;
107 inline bool IsEmpty() const;
108
109 inline int Width() const;
110 inline int Height() const;
111
112 inline void SetWidth(int w);
113 inline void SetHeight(int h);
114
115 friend inline bool operator==(const SizeI& s1, const SizeI& s2);
116 friend inline bool operator!=(const SizeI& s1, const SizeI& s2);
117
118 private:
119 int width_;
120 int height_;
121 };
122
SizeI()123 inline SizeI::SizeI() noexcept : width_(0.0), height_(0.0) {}
124
SizeI(const SizeI & s)125 inline SizeI::SizeI(const SizeI& s) noexcept : width_(s.Width()), height_(s.Height()) {}
126
SizeI(int w,int h)127 inline SizeI::SizeI(int w, int h) noexcept : width_(w), height_(h) {}
128
~SizeI()129 inline SizeI::~SizeI() noexcept {}
130
IsZero()131 inline bool SizeI::IsZero() const
132 {
133 return width_ == 0 && height_ == 0;
134 }
135
IsEmpty()136 inline bool SizeI::IsEmpty() const
137 {
138 return width_ <= 0 || height_ <= 0;
139 }
140
Width()141 inline int SizeI::Width() const
142 {
143 return width_;
144 }
145
Height()146 inline int SizeI::Height() const
147 {
148 return height_;
149 }
150
SetWidth(int w)151 inline void SizeI::SetWidth(int w)
152 {
153 width_ = w;
154 }
155
SetHeight(int h)156 inline void SizeI::SetHeight(int h)
157 {
158 height_ = h;
159 }
160
161 inline bool operator==(const SizeI& s1, const SizeI& s2)
162 {
163 return s1.width_ == s2.width_ && s1.height_ == s2.height_;
164 }
165
166 inline bool operator!=(const SizeI& s1, const SizeI& s2)
167 {
168 return s1.width_ != s2.width_ || s1.height_ != s2.height_;
169 }
170 } // namespace Drawing
171 } // namespace Rosen
172 } // namespace OHOS
173 #endif