-
Notifications
You must be signed in to change notification settings - Fork 13
/
UiPointF.h
113 lines (93 loc) · 1.85 KB
/
UiPointF.h
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
#ifndef UI_CORE_UIPOINTF_H_
#define UI_CORE_UIPOINTF_H_
#include "duilib/duilib_defs.h"
#include <cstdint>
namespace ui
{
/** 点的封装
*/
class UILIB_API UiPointF
{
public:
UiPointF()
{
x = y = 0;
}
UiPointF(float xValue, float yValue)
{
x = xValue;
y = yValue;
}
/** 设置新的X和Y值
*/
void SetXY(float xValue, float yValue)
{
x = xValue;
y = yValue;
}
/** 设置新的X值
*/
void SetX(float xValue) { x = xValue; }
/** 设置新的Y值
*/
void SetY(float yValue) { y = yValue; }
/** 偏移操作
*/
void Offset(float offsetX, float offsetY)
{
x += offsetX;
y += offsetY;
}
/** 偏移操作
*/
void Offset(const UiPointF& offsetPoint)
{
x += offsetPoint.x;
y += offsetPoint.y;
}
/** 返回x值
*/
constexpr float X() const { return x; }
/** 返回y值
*/
constexpr float Y() const { return y; }
/** 如果x和y都是0,返回true
*/
bool IsZero() const
{
return x == 0 && y == 0;
}
/** 判断是否与另外一个点相同
*/
bool Equals(float xValue, float yValue) const
{
return x == xValue && y == yValue;
}
/** 判断是否与另外一个点相同
*/
bool Equals(const UiPointF& dst) const
{
return x == dst.x && y == dst.y;
}
/** 判断两个值是否相等
*/
friend bool operator == (const UiPointF& a, const UiPointF& b)
{
return a.Equals(b);
}
/** 判断两个值是否不相等
*/
friend bool operator != (const UiPointF& a, const UiPointF& b)
{
return !a.Equals(b);
}
public:
/** X轴坐标
*/
float x;
/** Y轴坐标
*/
float y;
};
} // namespace ui
#endif // UI_CORE_UIPOINTF_H_