Commit bf7564c4 authored by ronan's avatar ronan
Browse files

Gestion fin des edges, quelques bugs restants, doit on supprimer even?

parent 6149b8ab
......@@ -8,6 +8,7 @@ class Edge:
self.vec = vec
self.p0 = p0
self.p1 = p1
self.c = False
def addPoint(self, p):
if self.p0 is None:
......@@ -16,11 +17,11 @@ class Edge:
assert(self.p1 is None)
self.p1 = p
def set(self, pV, i):
def set(self, p, i):
if i:
self.p1 = pV.center
self.p1 = p
else:
self.p0 = pV.center
self.p0 = p
def add(self, edge, i):
if i:
......@@ -48,7 +49,7 @@ class Edge:
if self.p1 is not None and self.p0 is not None:
self.p1.drawF(screen, fX, fY, "Red")
"""
if (self.p0 is None and self.p1 is not None) or (self.p0 is not None and self.p1 is None):
# On regarde les voisins précédents ou suivant
if len(self.prec) == 0 and len(self.next) == 0:
......@@ -89,10 +90,10 @@ class Edge:
else:
A = 0
if A != -1:
if A:
self.vec *= -1
if A == 1:
self.vec *= -1
if A != -1:
if abs(self.vec.getY()) > abs(self.vec.getX()):
if self.vec.getY() < 0.0:
if p.getY() > 0:
......@@ -114,4 +115,7 @@ class Edge:
if p.getX() < maxX:
fac = (maxX - p.getX())/abs(self.vec.getX())
y = p.getY() + fac*self.vec.getY()
screen.create_line(p.getX() * fX, p.getY() * fY, maxX * fX, y * fY)
\ No newline at end of file
screen.create_line(p.getX() * fX, p.getY() * fY, maxX * fX, y * fY)
"""
......@@ -10,6 +10,7 @@ class Fortune:
self.init(points, step)
def init(self, points, step):
self.alreadyDone = {}
self.points = []
for i in points:
self.points.append(i.copy())
......@@ -73,8 +74,8 @@ class Fortune:
if p is not None:
if p1 is not None and p3 is not None:
# On supprime les evenements liés aux anciens points
self.removeEvent(p1, p, p3)
#self.removeEvent(p1, p, p3)
pass
# Création du segment
# createEdge(p, site)
......@@ -171,8 +172,8 @@ class Fortune:
break
i -= 1
if len(site.sites) == 1:
pass
self.alreadyDone[Fortune.getChain(site)] = True
# test
for x in range(len(self.events)-1):
......@@ -180,6 +181,21 @@ class Fortune:
print("error")
self.events.insert(i+1, site)
@staticmethod
def getChain(site):
sites = list(site.sites)
for i in range(len(sites)):
for j in range(i+1, len(sites)):
if int(sites[i].name[1:]) > int(sites[j].name[1:]):
sites[i], sites[j] = sites[j], sites[i]
ch = ""
for i in range(len(sites)):
ch += sites[i].name
return ch
def removeEvent(self, p1, p, p3):
i = 0
while i < len(p.sites):
......@@ -203,6 +219,9 @@ class Fortune:
def isValidVertex(self, vSite):
if vSite is None:
return False
if Fortune.getChain(vSite) in self.alreadyDone:
return False
radius = (vSite.center - vSite.point).getMagnitude()
i = len(self.sites) - 1
while i > -1 and vSite.point.getY() >= self.sites[i].point.getY():
......
......@@ -59,17 +59,11 @@ class Node:
iNode2 = self.right.low()
c = None
breakpoints = computeBreakPoint(iNode1.site, iNode2.site, ly)
"""if len(breakpoints) == 2:
if iNode1.site.point.getY() < iNode2.site.point.getY():
c = breakpoints[0]
else:
c = breakpoints[1]
else:
assert(len(breakpoints) != 0)
c = breakpoints[0]"""
if len(breakpoints) != 0:
c = breakpoints[0]
self.value = c.getX()
self.edge.set(c, self.p)
if not self.left.isLeaf():
self.left.update(ly)
......@@ -209,12 +203,12 @@ class Node:
self.root.edge.test()
toModify.edge.test()
self.root.edge.set(p0, self.root.p)
self.root.edge.set(p0.center, self.root.p)
#self.root.edge.prec.append(toModify.edge)
self.root.edge.add(toModify.edge, self.root.p)
#toModify.edge.next.append(self.root.edge)
toModify.edge.add(self.root.edge, toModify.p)
toModify.edge.set(p0, toModify.p)
toModify.edge.set(p0.center, toModify.p)
tP = toModify.p
lastEdge = toModify.edge
......@@ -225,7 +219,7 @@ class Node:
#toModify.edge.prec.append(lastEdge)
toModify.edge.add(lastEdge, 0)
lastEdge.add(toModify.edge, tP)
toModify.edge.set(p0, 0)
toModify.edge.set(p0.center, 0)
toModify.p = 1
edges.append(toModify.edge)
......
......@@ -22,9 +22,14 @@ def step(event):
print("-------------")
print("")
"""
elif len(fortune.events) > 0:
fortune.beachLine.update(float((ly[0]+ 10))/fac.getY())
ly[0] += 10
else:
fortune.beachLine.update(float((ly[0]+ 10))/fac.getY())
ly[0] += 10
canvas.create_line(0, ly[0], 500, ly[0], fill="red")
for i in range(len(vec)):
a = vec[i].copy()
......@@ -40,7 +45,7 @@ def step(event):
a.setX(rE[i].point.getX() * fac.getX())
a.setY(rE[i].point.getY() * fac.getY())
a.draw(canvas)
#draw_Pol(canvas, a, ly[0])
draw_Pol(canvas, a, ly[0])
canvas.create_text(a.getX() - 10, a.getY() + 12, anchor=W, font="Arial 8", text=str(rE[i]))
E = fortune.events
......@@ -82,9 +87,10 @@ def step(event):
fortune.beachLine.draw(canvas, 1000, 100, 6)
def full(event):
global coords
if event is not None:
global coords
touche = event.keysym
touche = event.keysym
canvas.delete(ALL)
canvas.create_line(0, ly[0], 500, ly[0], fill="red")
......@@ -131,6 +137,7 @@ def mouse(event):
vec.append(a)
fortune.init(vec, False)
fortune.beachLine.update(float(fortune.rEvents[len(fortune.rEvents) - 1].point.getY() + 100)/fac.getY())
print(a)
full(event)
......@@ -142,15 +149,25 @@ def mouse(event):
def draw_Pol(screen, p, y):
fac = 10
fac = 5
start = 100
a = p.getY()*p.getY() - y*y
b = (2*(y - p.getY()))
x2 = p.getX() - start*fac
h = (p.getX() - x2)*(p.getX() - x2) + a
if b != 0.0:
for x in range(500):
x1 = x + p.getX() - 250
h = (p.getX() - x1)*(p.getX() - x1) + a
y1 = -h/b
screen.create_oval(x1 - 1, y1 - 1, x1 + 1, y1 + 1, fill='black')
y2 = -h/b
if b != 0.0:
for x in range(start*2):
x1 = x*fac + p.getX() - start*fac
h = (p.getX() - x1)*(p.getX() - x1) + a
y1 = -h/b
screen.create_line(x1, y1, x2, y2, fill='black')
x2 = x1
y2 = y1
if __name__ == "__main__":
......@@ -159,8 +176,16 @@ if __name__ == "__main__":
vec = []
vec.append(Vector3D(6.58333333, 1.1))
vec.append(Vector3D(6.1, 2))
vec.append(Vector3D(4, 1))
vec.append(Vector3D(9.5, 2.06666667))
vec.append(Vector3D(11.41666667,3.61666667))
vec.append(Vector3D(5, 2.7))
vec.append(Vector3D(3.2, 3))
vec.append(Vector3D(4.2, 4))
......@@ -170,10 +195,11 @@ if __name__ == "__main__":
vec.append(Vector3D(3, 8.2))
vec.append(Vector3D(1, 7))
start = [True]
for i in vec:
i.setY(i.getY() + 1)
i.setX(i.getX() + 5)
i.setY(i.getY() + 0)
i.setX(i.getX() + 0)
fac = Vector3D(60, 60)
ly = [0]
......@@ -182,11 +208,17 @@ if __name__ == "__main__":
canvas.focus_set()
fortune = Fortune(vec, True)
#full(None)
canvas.bind("<Key>", clavier)
canvas.bind("<Button-1>", mouse)
canvas.pack()
fenetre.mainloop()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment