-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCross.cpp
121 lines (105 loc) · 3.11 KB
/
Cross.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
#include "Cross.h"
using namespace std;
double Cross::ComputeArea() {
big_rec.setArea(big_rec.ComputeArea());
br_rec.setArea(br_rec.ComputeArea());
bl_rec.setArea(bl_rec.ComputeArea());
tl_rec.setArea(tl_rec.ComputeArea());
tr_rec.setArea(tr_rec.ComputeArea());
return big_rec.GetArea() - bl_rec.GetArea() - br_rec.GetArea() - tl_rec.GetArea() - tr_rec.GetArea();
}
bool Cross::isPointInShape(int x, int y) {
for(int i = 0; i < plist.size(); i++) {
if(plist[i]->getX() == x && plist[i]->getY() == y) {
return false;
}
}
if(isPointOnShape(x,y)) {
return false;
}
bool in_big_rec = big_rec.isPointInShape(x,y);
bool in_corner = tr_rec.isPointInShape(x,y)
|| tl_rec.isPointInShape(x,y)
|| bl_rec.isPointInShape(x,y)
|| br_rec.isPointInShape(x,y);
if(in_big_rec){
return (!in_corner);
}
return false;
}
bool Cross::isPointOnShape(int x, int y) {
for(int i = 0; i < plist.size(); i++) {
if(plist[i]->getX() == x && plist[i]->getY() == y) {
return false;
}
}
bool in_big_rec = big_rec.isPointOnShape(x,y);
bool in_corner = tr_rec.isPointOnShape(x,y)
|| tl_rec.isPointOnShape(x,y)
|| bl_rec.isPointOnShape(x,y)
|| br_rec.isPointOnShape(x,y);
return (in_big_rec^in_corner);
}
string Cross::toString() {
ostringstream oss;
ostringstream oss1;
ostringstream oss2;
string res;
oss << "Shape[" << GetId()<< "]" << endl;
oss << "Name : " << GetName() << endl;
oss << "Special Type : ";
if(GetContainsWarpSpace()) {
oss << "WS" << endl;
} else{
oss << "NS" << endl;
}
if(GetArea() != -1) {
oss << "Area : "<< setprecision(2) << fixed <<GetArea()<<" units square" << endl;
}
oss << "Vertices:" << endl;
for(int i=0; i<plist.size(); i++) {
oss << "Point [" << i << "] : (" << plist[i]->getX() << ", " << plist[i]->getY() << ")" << endl;
}
oss << endl;
int count_in = 0;
int count_on = 0;
for(int i = big_rec.p1.x;i <= big_rec.p2.x;i++){
for(int j = big_rec.p1.y;j <= big_rec.p2.y;j++){
if(isPointOnShape(i,j)) {
oss1 << "(" << i << ", " << j << "), ";
count_on++;
}
if(isPointInShape(i,j)) {
oss2 << "(" << i << ", " << j << "), ";
count_in++;
}
}
}
oss << "Points on perimeter: ";
if(count_on == 0) {
oss << "none!" << endl << endl;
} else {
res = oss1.str();
res.erase(res.size()-2);
oss << res << endl << endl;
}
oss << "Points within shape: ";
if(count_in == 0) {
oss << "none!" << endl << endl;
} else {
res = oss2.str();
res.erase(res.size()-2);
oss << res << endl << endl;
}
return oss.str();
}
bool compare_pointxy(Point *a, Point *b) {
if(a->x == b->x) {
return a->y < b->y;
} else {
return a->x < b->x;
}
}
vector<Point*> Cross::getList() {
return fulllist;
};