1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef VPOINT_H
#define VPOINT_H
#include "vector_vglobal.h"
V_BEGIN_NAMESPACE
class VPointF {
public:
VPointF() = default;
constexpr inline VPointF(float x, float y) noexcept : mx(x), my(y) {}
constexpr inline float x() const noexcept { return mx; }
constexpr inline float y() const noexcept { return my; }
inline float & rx() noexcept { return mx; }
inline float & ry() noexcept { return my; }
inline void setX(float x) { mx = x; }
inline void setY(float y) { my = y; }
inline VPointF operator-() noexcept { return {-mx, -my}; }
inline VPointF & operator+=(const VPointF &p) noexcept;
inline VPointF & operator-=(const VPointF &p) noexcept;
friend const VPointF operator+(const VPointF &p1, const VPointF &p2)
{
return VPointF(p1.mx + p2.mx, p1.my + p2.my);
}
inline friend bool fuzzyCompare(const VPointF &p1, const VPointF &p2);
inline friend VDebug & operator<<(VDebug &os, const VPointF &o);
friend inline VPointF operator-(const VPointF &p1, const VPointF &p2);
friend inline const VPointF operator*(const VPointF &, float);
friend inline const VPointF operator*(float, const VPointF &);
friend inline const VPointF operator/(const VPointF &, float);
friend inline const VPointF operator/(float, const VPointF &);
private:
float mx{0};
float my{0};
};
inline bool fuzzyCompare(const VPointF &p1, const VPointF &p2)
{
return (vCompare(p1.mx, p2.mx) && vCompare(p1.my, p2.my));
}
inline VPointF operator-(const VPointF &p1, const VPointF &p2)
{
return {p1.mx - p2.mx, p1.my - p2.my};
}
inline const VPointF operator*(const VPointF &p, float c)
{
return VPointF(p.mx * c, p.my * c);
}
inline const VPointF operator*(float c, const VPointF &p)
{
return VPointF(p.mx * c, p.my * c);
}
inline const VPointF operator/(const VPointF &p, float c)
{
return VPointF(p.mx / c, p.my / c);
}
inline const VPointF operator/(float c, const VPointF &p)
{
return VPointF(p.mx / c, p.my / c);
}
inline VDebug &operator<<(VDebug &os, const VPointF &o)
{
os << "{P " << o.x() << "," << o.y() << "}";
return os;
}
inline VPointF &VPointF::operator+=(const VPointF &p) noexcept
{
mx += p.mx;
my += p.my;
return *this;
}
inline VPointF &VPointF::operator-=(const VPointF &p) noexcept
{
mx -= p.mx;
my -= p.my;
return *this;
}
class VPoint {
public:
VPoint() = default;
constexpr inline VPoint(int x, int y) noexcept : mx(x), my(y) {}
constexpr inline int x() const noexcept { return mx; }
constexpr inline int y() const noexcept { return my; }
inline void setX(int x) { mx = x; }
inline void setY(int y) { my = y; }
inline VPoint & operator+=(const VPoint &p) noexcept;
inline VPoint & operator-=(const VPoint &p) noexcept;
constexpr inline bool operator==(const VPoint &o) const;
constexpr inline bool operator!=(const VPoint &o) const
{
return !(operator==(o));
}
friend inline VPoint operator-(const VPoint &p1, const VPoint &p2);
inline friend VDebug &operator<<(VDebug &os, const VPoint &o);
private:
int mx{0};
int my{0};
};
inline VDebug &operator<<(VDebug &os, const VPoint &o)
{
os << "{P " << o.x() << "," << o.y() << "}";
return os;
}
inline VPoint operator-(const VPoint &p1, const VPoint &p2)
{
return {p1.mx - p2.mx, p1.my - p2.my};
}
constexpr inline bool VPoint::operator==(const VPoint &o) const
{
return (mx == o.x() && my == o.y());
}
inline VPoint &VPoint::operator+=(const VPoint &p) noexcept
{
mx += p.mx;
my += p.my;
return *this;
}
inline VPoint &VPoint::operator-=(const VPoint &p) noexcept
{
mx -= p.mx;
my -= p.my;
return *this;
}
class VSize {
public:
VSize() = default;
constexpr inline VSize(int w, int h) noexcept : mw(w), mh(h) {}
bool empty() const {return (mw <= 0 || mh <= 0);}
constexpr inline int width() const noexcept { return mw; }
constexpr inline int height() const noexcept { return mh; }
inline void setWidth(int w) { mw = w; }
inline void setHeight(int h) { mh = h; }
inline VSize & operator+=(const VSize &p) noexcept;
inline VSize & operator-=(const VSize &p) noexcept;
constexpr inline bool operator==(const VSize &o) const;
constexpr inline bool operator!=(const VSize &o) const
{
return !(operator==(o));
}
inline friend VDebug &operator<<(VDebug &os, const VSize &o);
private:
int mw{0};
int mh{0};
};
inline VDebug &operator<<(VDebug &os, const VSize &o)
{
os << "{P " << o.width() << "," << o.height() << "}";
return os;
}
constexpr inline bool VSize::operator==(const VSize &o) const
{
return (mw == o.width() && mh == o.height());
}
inline VSize &VSize::operator+=(const VSize &p) noexcept
{
mw += p.mw;
mh += p.mh;
return *this;
}
inline VSize &VSize::operator-=(const VSize &p) noexcept
{
mw -= p.mw;
mh -= p.mh;
return *this;
}
V_END_NAMESPACE
#endif // VPOINT_H
|