Commit f4f94bd5 authored by ronan's avatar ronan
Browse files

Allégement de l'ajout des edges

parent 7443b07d
......@@ -6,12 +6,12 @@ class BeachLine:
def __init__(self):
self.root = None
def insert(self, p0):
def insert(self, p0, edges):
if self.root is None:
self.root = Node(p0)
return [None, None, None]
else:
return self.root.insert(p0)
return self.root.insert(p0, edges)
def update(self, ly):
if self.root is None or self.root.isLeaf():
......
......@@ -16,8 +16,16 @@ class Edge:
assert(self.p1 is None)
self.p1 = p
def set(self, p, i):
if i:
self.p1 = p
else:
self.p0 = p
def draw(self, screen, fX = 1.0, fY = 1.0):
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")
\ No newline at end of file
self.p0.drawF(screen, fX, fY, "Red")
if self.p1 is not None:
self.p1.drawF(screen, fX, fY, "Red")
\ No newline at end of file
......@@ -13,6 +13,7 @@ class Fortune:
self.beachLine = BeachLine()
self.vertex = []
self.rEvents = []
self.edges = []
# Sort Y
for i in range(len(self.points)):
for j in range(i+1, len(self.points)):
......@@ -42,12 +43,12 @@ class Fortune:
self.beachLine.update(self.events[len(self.events)-1].point.getY())
def handleSite(self):
site = self.events.pop(len(self.events)-1) #SweapLine
site = self.events.pop(len(self.events)-1) # SweapLine
if site.name == "p5":
pass
self.rEvents.append(site)
[p1, p, p3] = self.beachLine.insert(site) # Here <-----------------------
[p1, p, p3] = self.beachLine.insert(site, self.edges)
"""print("=== Site Ev ===")
print("Site = " + str(site))
......@@ -60,7 +61,7 @@ class Fortune:
self.removeEvent(p1, p, p3)
# Création du segment
createEdge(p, site)
# createEdge(p, site)
# AJout des breakpoints
if p1 is not None:
......@@ -83,8 +84,6 @@ class Fortune:
if vSite.type == 1:
on = vSite.sites[0] if vSite.sites[0] is not vSite.on else vSite.sites[2]
"""print("=== Vertex Ev ===")
print("Sites = " + str(vSite.sites[0]) + ", " + str(vSite.sites[1]) + ", " + str(vSite.sites[2]))
"""
......@@ -97,11 +96,12 @@ class Fortune:
print("=================")"""
if pi is not None and pk is not None:
vSite.edges[0].addPoint(vSite.center)
vSite.edges[1].addPoint(vSite.center)
#vSite.edges[0].addPoint(vSite.center)
#vSite.edges[1].addPoint(vSite.center)
self.vertex.append(vSite.center)
#self.vertex.append(vSite.center)
"""
if vSite.type == 0:
if not createEdgeIfNot(vSite.sites[0], vSite.sites[2]):
print("Normal?")
......@@ -109,6 +109,7 @@ class Fortune:
assert(vSite.sites[0] is not vSite.on and vSite.sites[2] is not vSite.on)
if not createEdgeIfNot(vSite.sites[0], vSite.sites[2]):
print("Normal?")
"""
# AJout des breakpoints
if p1 is not None and (p1 is not vSite.on):
......
......@@ -84,6 +84,8 @@ def createEdge(p0, p1, pointToAdd = None):
if pointToAdd is not None:
edge.addPoint(pointToAdd)
return edge
def createEdgeIfNot(p0, p1, pointToAdd = None):
i = 0
......@@ -127,11 +129,13 @@ def vertexVerif(min):
min.sites[i], min.sites[j] = min.sites[j], min.sites[i]
# Ajout des edges et set le type
if min.sites[1] is min.on: #min.sites[1].point.getY() <= min.sites[0].point.getY() and min.sites[1].point.getY() <= min.sites[2].point.getY():
if min.sites[1] is min.on: # min.sites[1].point.getY() <= min.sites[0].point.getY() and min.sites[1].point.getY() <= min.sites[2].point.getY():
min.type = 0
"""
edge = None
i = 0
while edge is None:
if min.sites[0].edges[i] in min.sites[1].edges:
edge = min.sites[0].edges[i]
......@@ -145,12 +149,15 @@ def vertexVerif(min):
edge = min.sites[2].edges[i]
i += 1
min.edges.append(edge)
"""
else: #if min.sites[1].point.getY() > min.sites[0].point.getY() and min.sites[1].point.getY() > min.sites[2].point.getY():
else: # if min.sites[1].point.getY() > min.sites[0].point.getY() and min.sites[1].point.getY() > min.sites[2].point.getY():
min.type = 1
"""
edge = None
i = 0
while edge is None:
if min.sites[0].edges[i] in min.sites[2].edges:
edge = min.sites[0].edges[i]
......@@ -166,6 +173,7 @@ def vertexVerif(min):
i += 1
min.edges.append(edge)
"""
"""
else:
min.type = 0
......@@ -187,7 +195,6 @@ def vertexVerif(min):
"""
def getPosCurve(p, x, y):
a = p.getY()*p.getY() - y*y
b = (2*(y - p.getY()))
......
from Geom import *
from tkinter import Tk, Canvas, Frame, BOTH, W
class Node:
def __init__(self, site = None):
def __init__(self, site=None, edge=None, p=0):
self.site = site
self.left = None
self.right = None
self.value = 0
self.stop = False
self.root = None
self.edge = edge
self.p = p
def copy(self):
copy = Node(self.site)
......@@ -17,17 +19,17 @@ class Node:
copy.stop = self.stop
copy.root = self.root
def insert(self, p0):
def insert(self, p0, edges):
if self.isLeaf():
p = self.site
p1 = self.lastSite()
p3 = self.nextSite()
self.split(p0)
self.split(p0, edges)
return [p1, p, p3]
elif self.value > p0.point.getX():
return self.left.insert(p0)
return self.left.insert(p0, edges)
else:
return self.right.insert(p0)
return self.right.insert(p0, edges)
def remove(self, p0):
if self.site is not None and self.site.name == "p8":
......@@ -37,24 +39,11 @@ class Node:
if piN.site in p0.sites:
pkN = self.next()
if pkN.site in p0.sites:
p1 = piN.lastSite()
p2 = pkN.nextSite()
pi = piN.site
pk = pkN.site
if self.root.left is self:
self.root.right.root = self.root.root
if self.root.root.left is self.root:
self.root.root.left = self.root.right
else:
self.root.root.right = self.root.right
else:
self.root.left.root = self.root.root
if self.root.root.left is self.root:
self.root.root.left = self.root.left
else:
self.root.root.right = self.root.left
self.eraseNode(p0)
return [p1, pi, pk, p2]
if self.isLeaf():
......@@ -89,7 +78,6 @@ class Node:
if not self.right.isLeaf():
self.right.update(ly)
def isLeaf(self):
return self.left is None and self.right is None
......@@ -149,8 +137,17 @@ class Node:
else:
return self.root.findRootLeft()
def split(self, p):
def split(self, p, edges):
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)
self.p = 0
self.right = Node()
self.right.edge = self.edge
self.right.p = 1
self.right.left = Node(p)
self.right.right = Node(self.site)
self.left = Node(self.site)
......@@ -166,6 +163,21 @@ class Node:
self.value = p.point.getY()
self.right.value = p.point.getY()
def eraseNode(self, p0):
self.root.edge.set(p0.center, self.root.p)
if self.root.left is self:
self.root.right.root = self.root.root
if self.root.root.left is self.root:
self.root.root.left = self.root.right
else:
self.root.root.right = self.root.right
else:
self.root.left.root = self.root.root
if self.root.root.left is self.root:
self.root.root.left = self.root.left
else:
self.root.root.right = self.root.left
def deep(self):
a = 1
b = 1
......
......@@ -64,13 +64,22 @@ def clavier(event):
a.draw(canvas)
canvas.create_text(a.getX() - 10, a.getY() + 12, anchor=W, font="Arial 8", text=str(E[i]))
"""
edgesA = []
edges = fortune.edges
for i in range(len(edges)):
edges[i].draw(canvas, fac.getX(), fac.getY())
if edges[i].p1 is not None:
print("A")
if edges[i].p0 is not None:
print("A")
"""
for i in range(len(fortune.sites)):
for j in range(len(fortune.sites[i].edges)):
if fortune.sites[i].edges[j] not in edgesA:
edgesA.append(fortune.sites[i].edges[j])
fortune.sites[i].edges[j].draw(canvas, fac.getX(), fac.getY())
"""
fortune.beachLine.draw(canvas, 1000, 100, 6)
......
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