-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
133 lines (130 loc) · 2.1 KB
/
test.py
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
def simplify(points):
if len(points) < 3:
return None
elif len(points) <= 5:
return points
flag = True
while flag:
flag = False
for i in range(len(points) - 1):
a = points[i]
b = points[i + 1]
dis = (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
if dis < 6:
c = [(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0]
points.pop(i)
points.pop(i)
points.insert(i, c)
if i < len(points) - 1:
flag = True
break
if len(points) <= 5:
flag = False
for i in range(len(points)):
point = points[i]
points[i] = [int(point[0]), int(point[1])]
return points
points = [
[
1706,
1122
],
[
1704,
1124
],
[
1704,
1125
],
[
1703,
1126
],
[
1703,
1131
],
[
1705,
1133
],
[
1705,
1134
],
[
1706,
1135
],
[
1708,
1135
],
[
1709,
1136
],
[
1710,
1136
],
[
1711,
1135
],
[
1712,
1135
],
[
1715,
1132
],
[
1715,
1131
],
[
1716,
1130
],
[
1716,
1129
],
[
1715,
1128
],
[
1715,
1126
],
[
1714,
1126
],
[
1713,
1125
],
[
1713,
1124
],
[
1712,
1123
],
[
1711,
1123
],
[
1710,
1122
]
]
new_points = simplify(points)
print(new_points)