-
Notifications
You must be signed in to change notification settings - Fork 40
/
test_overlay.py
58 lines (46 loc) · 1.31 KB
/
test_overlay.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
from overlay import *
from copy import deepcopy
d=[ Dcel(), Dcel() ]
pgon1 = [ [3,3], [9,3], [8,8], [4,8] ]
edges1 = [ [0,1], [1,2], [2,3], [3,0] ]
pgon2 = [ [1,1], [6,6], [10,2] ]
edges2 = [ [0,1], [1,2], [2,0] ]
d[0].load(pgon1, edges1)
d[1].load(pgon2, edges2)
D = Dcel()
D.hedges = d[0].hedges + d[1].hedges
D.vertices = d[0].vertices + d[1].vertices
s1 = []
for i in range(len(pgon1)-1):
s1.append([pgon1[i], pgon1[i+1]])
s1.append([pgon1[-1], pgon1[0]])
s2 = []
for i in range(len(pgon2)-1):
s2.append([pgon2[i], pgon2[i+1]])
s2.append([pgon2[-1], pgon2[0]])
ps1 = [Segment(i, Point(s1[i][0][0],s1[i][0][1]),
Point(s1[i][1][0],s1[i][1][1]), 0) for i in range(len(s1))]
ps2 = [Segment(i+len(s1), Point(s2[i][0][0],s2[i][0][1]),
Point(s2[i][1][0],s2[i][1][1]), 1) for i in range(len(s2))]
s = ps1+ps2
ints = overlay(s, D)
# get all boundary cycles
hl = deepcopy(D.hedges)
while len(hl) is not 0:
c = []
#print len(hl), ":",
e0 = hl.pop()
e = e0
c.append(e)
while True:
print e,
e1 = e.nexthedge
if e1 is not e0:
c.append(e1)
hl.remove(e1)
e = e1
else:
break
print
import pickle
pickle.dump(D, open('mydcel.pickle', 'w'))