updated licenses info
[platform/core/uifw/lottie-player.git] / src / vector / vpoint.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the LGPL License, Version 2.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     https://www.gnu.org/licenses/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef VPOINT_H
18 #define VPOINT_H
19
20 #include "vglobal.h"
21
22 V_BEGIN_NAMESPACE
23
24 class VPointF {
25 public:
26     VPointF() = default;
27     constexpr inline VPointF(float x, float y) noexcept : mx(x), my(y) {}
28     constexpr inline float x() const noexcept { return mx; }
29     constexpr inline float y() const noexcept { return my; }
30     inline float &         rx() noexcept { return mx; }
31     inline float &         ry() noexcept { return my; }
32     inline void            setX(float x) { mx = x; }
33     inline void            setY(float y) { my = y; }
34     inline VPointF         operator-() noexcept { return {-mx, -my}; }
35     inline VPointF &       operator+=(const VPointF &p) noexcept;
36     inline VPointF &       operator-=(const VPointF &p) noexcept;
37     friend const VPointF   operator+(const VPointF &p1, const VPointF &p2)
38     {
39         return VPointF(p1.mx + p2.mx, p1.my + p2.my);
40     }
41     inline friend bool fuzzyCompare(const VPointF &p1, const VPointF &p2);
42     inline friend VDebug &   operator<<(VDebug &os, const VPointF &o);
43
44     friend inline VPointF       operator-(const VPointF &p1, const VPointF &p2);
45     friend inline const VPointF operator*(const VPointF &, float val);
46     friend inline const VPointF operator*(float val, const VPointF &);
47     friend inline const VPointF operator/(const VPointF &, float val);
48     friend inline const VPointF operator/(float val, const VPointF &);
49
50 private:
51     float mx{0};
52     float my{0};
53 };
54
55 inline bool fuzzyCompare(const VPointF &p1, const VPointF &p2)
56 {
57     return (vCompare(p1.mx, p2.mx) && vCompare(p1.my, p2.my));
58 }
59
60 inline VPointF operator-(const VPointF &p1, const VPointF &p2)
61 {
62     return {p1.mx - p2.mx, p1.my - p2.my};
63 }
64
65 inline const VPointF operator*(const VPointF &p, float c)
66 {
67     return VPointF(p.mx * c, p.my * c);
68 }
69
70 inline const VPointF operator*(float c, const VPointF &p)
71 {
72     return VPointF(p.mx * c, p.my * c);
73 }
74
75 inline const VPointF operator/(const VPointF &p, float c)
76 {
77     return VPointF(p.mx / c, p.my / c);
78 }
79
80 inline const VPointF operator/(float c, const VPointF &p)
81 {
82     return VPointF(p.mx / c, p.my / c);
83 }
84
85 inline VDebug &operator<<(VDebug &os, const VPointF &o)
86 {
87     os << "{P " << o.x() << "," << o.y() << "}";
88     return os;
89 }
90
91 inline VPointF &VPointF::operator+=(const VPointF &p) noexcept
92 {
93     mx += p.mx;
94     my += p.my;
95     return *this;
96 }
97
98 inline VPointF &VPointF::operator-=(const VPointF &p) noexcept
99 {
100     mx -= p.mx;
101     my -= p.my;
102     return *this;
103 }
104
105 class VPoint {
106 public:
107     VPoint() = default;
108     constexpr inline VPoint(int x, int y) noexcept : mx(x), my(y) {}
109     constexpr inline int  x() const noexcept { return mx; }
110     constexpr inline int  y() const noexcept { return my; }
111     inline void           setX(int x) { mx = x; }
112     inline void           setY(int y) { my = y; }
113     inline VPoint &       operator+=(const VPoint &p) noexcept;
114     inline VPoint &       operator-=(const VPoint &p) noexcept;
115     constexpr inline bool operator==(const VPoint &o) const;
116     constexpr inline bool operator!=(const VPoint &o) const
117     {
118         return !(operator==(o));
119     }
120     friend inline VPoint  operator-(const VPoint &p1, const VPoint &p2);
121     inline friend VDebug &operator<<(VDebug &os, const VPoint &o);
122
123 private:
124     int mx{0};
125     int my{0};
126 };
127 inline VDebug &operator<<(VDebug &os, const VPoint &o)
128 {
129     os << "{P " << o.x() << "," << o.y() << "}";
130     return os;
131 }
132
133 inline VPoint operator-(const VPoint &p1, const VPoint &p2)
134 {
135     return {p1.mx - p2.mx, p1.my - p2.my};
136 }
137
138 constexpr inline bool VPoint::operator==(const VPoint &o) const
139 {
140     return (mx == o.x() && my == o.y());
141 }
142
143 inline VPoint &VPoint::operator+=(const VPoint &p) noexcept
144 {
145     mx += p.mx;
146     my += p.my;
147     return *this;
148 }
149
150 inline VPoint &VPoint::operator-=(const VPoint &p) noexcept
151 {
152     mx -= p.mx;
153     my -= p.my;
154     return *this;
155 }
156
157 class VSize {
158 public:
159     VSize() = default;
160     constexpr inline VSize(int w, int h) noexcept : mw(w), mh(h) {}
161     bool empty() const {return (mw <= 0 || mh <= 0);}
162     constexpr inline int  width() const noexcept { return mw; }
163     constexpr inline int  height() const noexcept { return mh; }
164     inline void           setWidth(int w) { mw = w; }
165     inline void           setHeight(int h) { mh = h; }
166     inline VSize &        operator+=(const VSize &p) noexcept;
167     inline VSize &        operator-=(const VSize &p) noexcept;
168     constexpr inline bool operator==(const VSize &o) const;
169     constexpr inline bool operator!=(const VSize &o) const
170     {
171         return !(operator==(o));
172     }
173     inline friend VDebug &operator<<(VDebug &os, const VSize &o);
174
175 private:
176     int mw{0};
177     int mh{0};
178 };
179 inline VDebug &operator<<(VDebug &os, const VSize &o)
180 {
181     os << "{P " << o.width() << "," << o.height() << "}";
182     return os;
183 }
184 constexpr inline bool VSize::operator==(const VSize &o) const
185 {
186     return (mw == o.width() && mh == o.height());
187 }
188
189 inline VSize &VSize::operator+=(const VSize &p) noexcept
190 {
191     mw += p.mw;
192     mh += p.mh;
193     return *this;
194 }
195
196 inline VSize &VSize::operator-=(const VSize &p) noexcept
197 {
198     mw -= p.mw;
199     mh -= p.mh;
200     return *this;
201 }
202
203 V_END_NAMESPACE
204
205 #endif  // VPOINT_H