• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
33     inline bool IsZero() const;
34     inline bool IsEmpty() const;
35 
36     inline scalar Width() const;
37     inline scalar Height() const;
38 
39     inline void SetWidth(scalar w);
40     inline void SetHeight(scalar h);
41 
42     friend inline bool operator==(const SizeF& s1, const SizeF& s2);
43     friend inline bool operator!=(const SizeF& s1, const SizeF& s2);
44 
45 private:
46     scalar width_;
47     scalar height_;
48 };
49 
SizeF()50 inline SizeF::SizeF() noexcept : width_(0.0), height_(0.0) {}
51 
SizeF(const SizeF & s)52 inline SizeF::SizeF(const SizeF& s) noexcept : width_(s.Width()), height_(s.Height()) {}
53 
SizeF(scalar w,scalar h)54 inline SizeF::SizeF(scalar w, scalar h) noexcept : width_(w), height_(h) {}
55 
IsZero()56 inline bool SizeF::IsZero() const
57 {
58     return width_ == 0 && height_ == 0;
59 }
60 
IsEmpty()61 inline bool SizeF::IsEmpty() const
62 {
63     return width_ <= 0 || height_ <= 0;
64 }
65 
Width()66 inline scalar SizeF::Width() const
67 {
68     return width_;
69 }
70 
Height()71 inline scalar SizeF::Height() const
72 {
73     return height_;
74 }
75 
SetWidth(scalar w)76 inline void SizeF::SetWidth(scalar w)
77 {
78     width_ = w;
79 }
80 
SetHeight(scalar h)81 inline void SizeF::SetHeight(scalar h)
82 {
83     height_ = h;
84 }
85 
86 inline bool operator==(const SizeF& s1, const SizeF& s2)
87 {
88     return s1.width_ == s2.width_ && s1.height_ == s2.height_;
89 }
90 
91 inline bool operator!=(const SizeF& s1, const SizeF& s2)
92 {
93     return s1.width_ != s2.width_ || s1.height_ != s2.height_;
94 }
95 
96 class SizeI {
97 public:
98     inline SizeI() noexcept;
99     inline SizeI(const SizeI& s) noexcept;
100     inline SizeI(int w, int h) noexcept;
101 
102     inline bool IsZero() const;
103     inline bool IsEmpty() const;
104 
105     inline int Width() const;
106     inline int Height() const;
107 
108     inline void SetWidth(int w);
109     inline void SetHeight(int h);
110 
111     friend inline bool operator==(const SizeI& s1, const SizeI& s2);
112     friend inline bool operator!=(const SizeI& s1, const SizeI& s2);
113 
114 private:
115     int width_;
116     int height_;
117 };
118 
SizeI()119 inline SizeI::SizeI() noexcept : width_(0.0), height_(0.0) {}
120 
SizeI(const SizeI & s)121 inline SizeI::SizeI(const SizeI& s) noexcept : width_(s.Width()), height_(s.Height()) {}
122 
SizeI(int w,int h)123 inline SizeI::SizeI(int w, int h) noexcept : width_(w), height_(h) {}
124 
IsZero()125 inline bool SizeI::IsZero() const
126 {
127     return width_ == 0 && height_ == 0;
128 }
129 
IsEmpty()130 inline bool SizeI::IsEmpty() const
131 {
132     return width_ <= 0 || height_ <= 0;
133 }
134 
Width()135 inline int SizeI::Width() const
136 {
137     return width_;
138 }
139 
Height()140 inline int SizeI::Height() const
141 {
142     return height_;
143 }
144 
SetWidth(int w)145 inline void SizeI::SetWidth(int w)
146 {
147     width_ = w;
148 }
149 
SetHeight(int h)150 inline void SizeI::SetHeight(int h)
151 {
152     height_ = h;
153 }
154 
155 inline bool operator==(const SizeI& s1, const SizeI& s2)
156 {
157     return s1.width_ == s2.width_ && s1.height_ == s2.height_;
158 }
159 
160 inline bool operator!=(const SizeI& s1, const SizeI& s2)
161 {
162     return s1.width_ != s2.width_ || s1.height_ != s2.height_;
163 }
164 } // namespace Drawing
165 } // namespace Rosen
166 } // namespace OHOS
167 #endif