Commit 6149b8ab authored by ronan's avatar ronan
Browse files

Peut être fonctionnement de la fin des edges

Un bug encore à corriger
parent 7bee7688
......@@ -21,6 +21,8 @@ class BeachLine:
def remove(self, p0, edges):
assert(self.root is not None)
a = self.root.remove(p0, edges)
if a is None:
pass
assert(a is not None)
return a
......
......@@ -16,43 +16,102 @@ class Edge:
assert(self.p1 is None)
self.p1 = p
def set(self, p, i):
def set(self, pV, i):
if i:
self.p1 = p
self.p1 = pV.center
else:
self.p0 = p
self.p0 = pV.center
def add(self, edge, i):
if i:
self.next.append(edge)
else:
self.prec.append(edge)
def test(self):
if self.p0 is None:
if len(self.prec) != 0:
pass
if self.p1 is None:
if len(self.next) != 0:
pass
def draw(self, screen, fX = 1.0, fY = 1.0, maxX = 10, maxY = 10):
if self.p0 is not None and self.p1 is not None:
screen.create_line(self.p0.getX() * fX, self.p0.getY() * fY, self.p1.getX() * fX, self.p1.getY() * fY)
if self.p0 is not None:
self.p0.drawF(screen, fX, fY, "Red")
elif self.p1 is not None:
p = self.p1
if self.vec.getY() > self.vec.getX():
if p.getY() > 0:
fac = p.getY()/abs(self.vec.getY())
x = p.getX() + fac*self.vec.getX()
screen.create_line(p.getX() * fX, p.getY() * fY, x * fX, 0.0)
else:
if p.getX() > 0:
fac = p.getX()/abs(self.vec.getX())
y = p.getY() + fac*self.vec.getY()
screen.create_line(p.getX() * fX, p.getY() * fY, 0.0, y * fY)
if self.p1 is not None:
if self.p1 is not None and self.p0 is not None:
self.p1.drawF(screen, fX, fY, "Red")
elif self.p0 is not None:
p = self.p0
if self.vec.getY() > self.vec.getX():
if p.getY() < maxY:
fac = (maxY - p.getY())/abs(self.vec.getY())
x = p.getX() + fac*self.vec.getX()
screen.create_line(p.getX() * fX, p.getY() * fY, x * fX, maxY * fY)
else:
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
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:
print("aa")
assert(len(self.prec) == 0 or len(self.next) == 0)
p = self.p0 if self.p0 is not None else self.p1
A = -1
if len(self.prec) != 0:
for i in range(len(self.prec)):
if self.prec[i].p0 is not None and self.prec[i].p1 is not None:
p1 = self.prec[i].p0 if self.prec[i].p0 is not p else self.prec[i].p1
assert(p1 is not p)
vec = p - p1
s = vec * self.vec
if A == 1 and s > 0:
print("??qsf")
elif A == 0 and s < 0:
print("??qsf")
if s < 0:
A = 1
else:
A = 0
if len(self.next) != 0:
for i in range(len(self.next)):
if self.next[i].p0 is not None and self.next[i].p1 is not None:
p1 = self.next[i].p0 if self.next[i].p0 is not p else self.next[i].p1
assert(p1 is not p)
vec = p - p1
s = vec * self.vec
if A == 1 and s > 0:
print("??qsf")
elif A == 0 and s < 0:
print("??qsf")
if s < 0:
A = 1
else:
A = 0
if A != -1:
if A:
self.vec *= -1
if abs(self.vec.getY()) > abs(self.vec.getX()):
if self.vec.getY() < 0.0:
if p.getY() > 0:
fac = p.getY()/abs(self.vec.getY())
x = p.getX() + fac*self.vec.getX()
screen.create_line(p.getX() * fX, p.getY() * fY, x * fX, 0.0)
else:
if p.getY() < maxY:
fac = (maxY - p.getY())/abs(self.vec.getY())
x = p.getX() + fac*self.vec.getX()
screen.create_line(p.getX() * fX, p.getY() * fY, x * fX, maxY * fY)
else:
if self.vec.getX() < 0.0:
if p.getX() > 0:
fac = p.getX()/abs(self.vec.getX())
y = p.getY() + fac*self.vec.getY()
screen.create_line(p.getX() * fX, p.getY() * fY, 0.0, y * fY)
else:
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
......@@ -7,7 +7,13 @@ import math
class Fortune:
def __init__(self, points, step = False):
self.points = points
self.init(points, step)
def init(self, points, step):
self.points = []
for i in points:
self.points.append(i.copy())
self.sites = []
self.events = []
self.beachLine = BeachLine()
......@@ -19,6 +25,9 @@ class Fortune:
for j in range(i+1, len(self.points)):
if self.points[i].getY() < self.points[j].getY():
self.points[i], self.points[j] = self.points[j], self.points[i]
elif self.points[i].getY() == self.points[j].getY():
if self.points[i].getX() < self.points[j].getX():
self.points[i], self.points[j] = self.points[j], self.points[i]
# Convert points into sites and create events
for i in range(len(self.points)):
......@@ -29,6 +38,7 @@ class Fortune:
if not step:
self.create()
def create(self):
while len(self.events) != 0:
self.beachLine.update(self.events[len(self.events)-1].point.getY())
......@@ -44,8 +54,8 @@ class Fortune:
self.handleVertex()
else:
self.handleSite()
self.beachLine.update(self.events[len(self.events)-1].point.getY())
if len(self.events) > 0:
self.beachLine.update(self.events[len(self.events)-1].point.getY())
def handleSite(self):
site = self.events.pop(len(self.events)-1) # SweapLine
......@@ -179,9 +189,14 @@ class Fortune:
self.events.remove(p.sites[i])
else:
print("Nope")
p1.sites.remove(p.sites[i])
p3.sites.remove(p.sites[i])
p.sites.remove(p.sites[i])
if p3 is not p1:
p3.sites.remove(p.sites[i])
if p is not p1 and p is not p3:
p.sites.remove(p.sites[i])
i -= 1
i += 1
......
......@@ -90,7 +90,10 @@ def computeBreakPoint(p1, p2, ly):
def createEdge(p0, p1, pointToAdd = None):
vec = None
vec = p1.point - p0.point
vec.normalize()
edge = Edge(Vector3D(-vec.getY(), vec.getX()))
......
......@@ -155,11 +155,13 @@ class Node:
# Donc le node actuel a le premier point et le node à droite le second
self.edge = createEdge(p, self.site)
edges.append(self.edge)
"""
if self.root is not None:
self.edge.prec.append(self.root.edge)
self.root.edge.next.append(self.edge)
"""
if isNull(p.point.getY() - self.site.point.getY()):
self.p = 1
......@@ -204,19 +206,34 @@ class Node:
if self.root is toModify:
toModify = pkN[1]
self.root.edge.set(p0.center, self.root.p)
self.root.edge.prec.append(toModify.edge)
toModify.edge.next.append(self.root.edge)
toModify.edge.set(p0.center, toModify.p)
self.root.edge.test()
toModify.edge.test()
self.root.edge.set(p0, 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)
tP = toModify.p
lastEdge = toModify.edge
self.root.edge.test()
toModify.edge.test()
toModify.edge = createEdge(piN[0].site, pkN[0].site)
toModify.edge.prec.append(lastEdge)
lastEdge.next.append(lastEdge)
toModify.edge.set(p0.center, 0)
#toModify.edge.prec.append(lastEdge)
toModify.edge.add(lastEdge, 0)
lastEdge.add(toModify.edge, tP)
toModify.edge.set(p0, 0)
toModify.p = 1
edges.append(toModify.edge)
lastEdge.test()
self.root.edge.test()
toModify.edge.test()
if self.root.left is self:
self.root.right.root = self.root.root
if self.root.root.left is self.root:
......
......@@ -5,13 +5,12 @@ from VSite import VSite
import time
import math
def clavier(event):
def step(event):
global coords
touche = event.keysym
canvas.delete(ALL)
if (ly[0]+ 10)/fac.getY() >= fortune.events[len(fortune.events) - 1].point.getY():
if len(fortune.events) > 0 and (ly[0]+ 10)/fac.getY() >= fortune.events[len(fortune.events) - 1].point.getY():
ly[0] = fortune.events[len(fortune.events) - 1].point.getY()*fac.getY()
before = fortune.beachLine.array()
fortune.createStep()
......@@ -33,6 +32,7 @@ def clavier(event):
a.setY(vec[i].getY() * fac.getY())
a.draw(canvas)
rE = fortune.rEvents
for i in range(len(rE)):
if type(rE[i]) is not VSite:
......@@ -40,7 +40,7 @@ def clavier(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
......@@ -81,6 +81,62 @@ def clavier(event):
fortune.beachLine.draw(canvas, 1000, 100, 6)
def full(event):
global coords
touche = event.keysym
canvas.delete(ALL)
canvas.create_line(0, ly[0], 500, ly[0], fill="red")
for i in range(len(vec)):
a = vec[i].copy()
a.setX(vec[i].getX() * fac.getX())
a.setY(vec[i].getY() * fac.getY())
a.draw(canvas)
edges = fortune.edges
for i in range(len(edges)):
edges[i].draw(canvas, fac.getX(), fac.getY(), 20, 20)
def clavier(event):
if start[0]:
fortune.init(vec, True)
start[0] = False
ly[0] = 0
step(event)
def mouse(event):
a = Vector3D(float(event.x)/fac.getX(), float(event.y)/fac.getY())
"""
point = len(vec) - 1
max = 5
magn = max + 1.0
while point > -1 and (vec[point] - a).getMagnitude() > max:
point -= 1
if point == -1:
vec.append(a)
print("Add")
""
else:
print("Mo")
vecA = a - mousePos
vec[point] += vecA
""
fortune.init(vec, False)
"""
vec.append(a)
fortune.init(vec, False)
print(a)
full(event)
start[0] = True
......@@ -101,26 +157,33 @@ if __name__ == "__main__":
fenetre = Tk()
canvas = Canvas(fenetre, width=1600, height=900, background='white')
vec = []
vec.append(Vector3D(2, 1))
vec.append(Vector3D(6.1, 2))
vec.append(Vector3D(4, 1))
vec.append(Vector3D(5, 2.7))
vec.append(Vector3D(3.2, 3))
vec.append(Vector3D(4.2, 4))
vec.append(Vector3D(5.2, 5))
vec.append(Vector3D(3.1, 5))
vec.append(Vector3D(5.2, 5.1))
vec.append(Vector3D(3.1, 5.2))
vec.append(Vector3D(1, 5))
vec.append(Vector3D(3, 8.2))
vec.append(Vector3D(5.4, 7))
vec.append(Vector3D(1, 7))
start = [True]
for i in vec:
i.setY(i.getY() + 1)
i.setX(i.getX() + 5)
fac = Vector3D(60, 60)
ly = [0]
mousePos = Vector3D(-1, -1)
canvas.focus_set()
fortune = Fortune(vec, True)
canvas.bind("<Key>", clavier)
canvas.bind("<Button-1>", mouse)
canvas.pack()
......
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