-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMappedRect.cpp
188 lines (182 loc) · 4.79 KB
/
MappedRect.cpp
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
#include "StdAfx.h"
#include "MappedRect.h"
const bool MappedRect::operator==(const MappedRect& CompareRect) const {
return (BasicRect == CompareRect.BasicRect) &&
(Scanned == CompareRect.Scanned) &&
(ScanUsed == CompareRect.ScanUsed) &&
(ScanY == CompareRect.ScanY) &&
(ScanX == CompareRect.ScanX) &&
(Rg == CompareRect.Rg);
}
const bool MappedRect::operator!=(const MappedRect& CompareRect) const {
return !(*this == CompareRect);
}
const MappedRect& MappedRect::operator=(const MappedRect& CompareRect) {
if (*this != CompareRect) {
BasicRect = CompareRect.BasicRect;
Scanned = CompareRect.Scanned;
ScanUsed = CompareRect.ScanUsed;
ScanY = CompareRect.ScanY;
ScanX = CompareRect.ScanX;
Rg = CompareRect.Rg;
}
return *this;
}
const MappedRect& MappedRect::operator=(const RECT& CompareRect) {
if (BasicRect != CompareRect) {
BasicRect = CompareRect;
}
return *this;
}
const bool MappedRect::operator<(const MappedRect& CompareRect) const {
return Rg < CompareRect.Rg;
}
const bool MappedRect::operator<=(const MappedRect& CompareRect) const {
return (*this == CompareRect) || (*this < CompareRect);
}
const bool MappedRect::operator>(const MappedRect& CompareRect) const {
return Rg > CompareRect.Rg;
}
const bool MappedRect::operator>=(const MappedRect& CompareRect) const {
return (*this == CompareRect) || (*this > CompareRect);
}
//initialization
MappedRect::MappedRect() {
BasicRect.top = BasicRect.right = BasicRect.left = BasicRect.bottom = 0;
ScanX = Left;
ScanY = Top;
ScanUsed = Vertical;
Rg = 0;
Scanned = false;
}
MappedRect::MappedRect(const MappedRect& CopyRect) {
ScanX = Left;
ScanY = Top;
ScanUsed = Vertical;
Rg = 0;
*this = CopyRect;
}
MappedRect::MappedRect(RECT CopyRect) {
ScanX = Left;
ScanY = Top;
ScanUsed = Vertical;
Rg = 0;
*this = CopyRect;
}
MappedRect::MappedRect(const POINT TopLeft, const POINT BottomRight) {
BasicRect.top = TopLeft.y;
BasicRect.left = TopLeft.x;
BasicRect.bottom = BottomRight.y;
BasicRect.right = BottomRight.x;
ScanX = Left;
ScanY = Top;
ScanUsed = Vertical;
Rg = 0;
Scanned = false;
}
MappedRect::MappedRect(const LONG Tx, const LONG Ty, const LONG Bx, const LONG By) {
BasicRect.top = Ty;
BasicRect.left = Tx;
BasicRect.bottom = By;
BasicRect.right = Bx;
ScanX = Left;
ScanY = Top;
ScanUsed = Vertical;
Rg = 0;
Scanned = false;
}
MappedRect::~MappedRect() {
}
const POINT MappedRect::TopLeft() const {
POINT ReturnPoint;
ReturnPoint.x = BasicRect.left;
ReturnPoint.y = BasicRect.top;
return ReturnPoint;
}
const POINT MappedRect::TopRight() const {
POINT ReturnPoint;
ReturnPoint.x = BasicRect.right;
ReturnPoint.y = BasicRect.top;
return ReturnPoint;
}
const POINT MappedRect::BottomLeft() const {
POINT ReturnPoint;
ReturnPoint.x = BasicRect.left;
ReturnPoint.y = BasicRect.bottom;
return ReturnPoint;
}
const POINT MappedRect::BottomRight() const {
POINT ReturnPoint;
ReturnPoint.x = BasicRect.right;
ReturnPoint.y = BasicRect.bottom;
return ReturnPoint;
}
const POINT MappedRect::GetCoordinateFromLocation(HorizontalStart HorzStart, VerticalStart VertStart) const {
if (HorzStart == Left && VertStart == Top) {
return TopLeft();
}
else if (HorzStart == Right && VertStart == Top) {
return TopRight();
}
else if (HorzStart == Left && VertStart == Bottom) {
return BottomLeft();
}
else if (HorzStart == Right && VertStart == Bottom) {
return BottomRight();
}
POINT DummyPoint;
DummyPoint.x = DummyPoint.y = 0;
return DummyPoint;
}
const MappedLine MappedRect::GetDiagonal() const {
return MappedLine(BasicRect.left, BasicRect.top, BasicRect.right, BasicRect.bottom);
}
const bool MappedRect::IsSquare() const {
return GetDiagonal().Slope() == (double)1.0;
}
const POINT MappedRect::RectCenter() const {
return GetDiagonal().Midpoint();
}
//rectangle analysis function
const POINT MappedRect::FindClosestVertex(POINT FindPoint) const {
POINT ReturnPoint = FindPoint, ComparePoint = FindPoint;
double ReturnDist = 0, CompareBuffer = 0;
for (int FindLoop = 0; FindLoop <= 3; ++FindLoop) {
switch (FindLoop) {
case 0:
ComparePoint = TopLeft();
break;
case 1:
ComparePoint = TopRight();
break;
case 2:
ComparePoint = BottomLeft();
break;
case 3:
ComparePoint = BottomRight();
break;
}
CompareBuffer = GeometricObject::Range(ComparePoint, FindPoint);
if (FindLoop == 0 || CompareBuffer < ReturnDist) { //for calibration
ReturnPoint = ComparePoint;
ReturnDist = CompareBuffer;
}
}
return ReturnPoint;
}
void MappedRect::ReadData(FileStream& File) {
File >> BasicRect.top;
File >> BasicRect.bottom;
File >> BasicRect.left;
File >> BasicRect.right;
File >> Rg;
File >> Scanned;
}
void MappedRect::WriteData(FileStream& File) const {
File << BasicRect.top;
File << BasicRect.bottom;
File << BasicRect.left;
File << BasicRect.right;
File << Rg;
File << Scanned;
}