-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
116 lines (103 loc) · 2.83 KB
/
main.cpp
File metadata and controls
116 lines (103 loc) · 2.83 KB
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
#include <bits/stdc++.h>
#include "pointHeaders.h"
using namespace std;
int main()
{
cout << "Alina Fedyna. This program calculates minimal distance between two points not crossing the polygon\n";
ifstream fi; ofstream fo;
string fName;
while (!fi.is_open()) //âõ³äíèé ôàéë
{
fName=getFileName("input");
if (fName=="") fName="input.txt";
fi.open(fName);
if (!fi.is_open()) cout << "Pass is incorrect\n";
}
fName=getFileName("output"); // âèõ³äíèé ôàéë
if (fName=="") fName="output.txt";
fo.open(fName);
Point p[N]; // òî÷êè ìíîãîêóòíèêà
int n=0;
p[0].setX(fi), p[0].setY(fi);
do{
++n;
p[n].setX(fi);
p[n].setY(fi);
} while (p[n]!=p[0]);
if (!is_ok(p,n)) return fo <<"Polygon is not correct", 0; // ïåðåâ³ðêà íà îïóêë³ñòü
Point a,b;
while (a.setX(fi)) //îáðîáêà òî÷îê
{
a.setY(fi); b.setX(fi); b.setY(fi);
if (a.is_inside(p,n) || b.is_inside(p,n)) fo << "Error: the point is inside the polygon\n";
else
{
if (cross(a,b,p,n))
{
Point ans1[N], ans2[N];
int ansN1=0, ansN2=0,k=0;
fo << getAns(a,b,p,n,ans1,ansN1,ans2,ansN2,k) << ": ";
if (k==1)
for (int i=0; i<ansN1; i++)
fo << ans1[i].getX() << " " << ans1[i].getY() << " ";
else{
for (int i=0; i<ansN2; i++)
fo << ans2[i].getX() << " " << ans2[i].getY() << " ";
}
fo << "\n";
}
else
{
fo << a.getLen(b) << ": ";
fo << a.getX() << " " << a.getY() << " " << b.getX() << " " << b.getY() << "\n";
}
}
}
fi.close();
fo.close();
return 0;
}
string getFileName(string t)
{
string name;
cout << "Enter pass to " << t <<" file: ";
getline(cin, name);
return name;
}
/*
bool is_ok(Point p[], int n)
{
if (n<3) return true;
int flag, k;
flag=p[2].def(p[0],p[1]);
for (int i=3; i<=n; ++i)
{
k=p[i].def(p[i-2],p[i-1]);
if (flag!=k) return false;
}
k=p[1].def(p[n-1],p[n]);
if (flag!=k) return false;
return true;
}
*/
bool is_ok(Point p[], int n)
{
if (n<3) return true;
int flag=0, k;
int ff=2;
while (flag==0 && ff<=n)
{
flag=p[ff].def(p[ff-2],p[ff-1]);
++ff;
}
if (flag==0) k=p[1].def(p[n-1],p[n]);
if (flag==0) return false;
for (int i=2; i<=n; ++i)
{
k=p[i].def(p[i-2],p[i-1]);
if (flag!=k && k!=0) return false;
}
k=p[1].def(p[n-1],p[n]);
if (flag!=k) return false;
return true;
}