Commit e3b81339 authored by ronan's avatar ronan
Browse files

BreakPoint corrigé

parent 9d841983
......@@ -20,15 +20,25 @@ class BeachLine:
def remove(self, p0):
assert(self.root is not None)
self.root.remove(p0)
a = self.root.remove(p0)
assert(a is not None)
return a
def removeFromVSite(self, vSite):
p = vSite.sites
for i in range(len(p)):
for j in range(i+1, len(p)):
if p[i].point.getX() < p[i].point.getX():
p[i], p[j] = p[j], p[i]
self.remove(vSite)
if p[i].point.getX() > p[j].point.getX():
assert(False)
if vSite.type == 1:
i = 0
while vSite.sites[i] is not vSite.on:
i+=1
assert(i != 1)
vSite.sites[i] = vSite.sites[1]
vSite.sites[1] = vSite.on
return self.remove(vSite)
def draw(self, screen, x, y, sizeD):
if self.root is not None:
......
......@@ -38,8 +38,8 @@ class Fortune:
self.beachLine.update(self.events[len(self.events)-1].point.getY())
if type(self.events[len(self.events)-1]) == VSite:
self.stop = True
#self.handleVertex()
#self.stop = True
self.handleVertex()
else:
self.handleSite()
......@@ -61,24 +61,26 @@ class Fortune:
createEdge(p, site)
if p1 is not None:
min = findMinCircle(p1, p, site)
min.on = p
if min.point.getY() > site.point.getY():
vertexVerif(min)
self.addEvent(min)
if p3 is not None:
min = findMinCircle(p3, p, site)
min.on = p
if min.point.getY() > site.point.getY():
vertexVerif(min)
self.addEvent(min)
def handleVertex(self):
vSite = self.events.pop(len(self.events)-1)
print("=== Vertex Ev ===")
print("Sites = " + str(vSite.sites[0]) + ", " + str(vSite.sites[1]) + ", " + str(vSite.sites[2]))
self.rEvents.append(vSite)
[p1, pi, pk, p2] = self.beachLine.removeFromVSite(vSite)
[p1, pi, pk, p2] = self.beachLine.removeFromVSite(vSite)
print("remove-> " + str(p1) + ", " + str(pi) + ", " + str(pk) + ", " + str(p2))
print("=================")
......@@ -107,12 +109,14 @@ class Fortune:
self.removeEvent(p1, pi, vSite)
min = findMinCircle(p1, pi, pk)
if min.point.getY() > vSite.point.getY():
vertexVerif(min)
self.addEvent(min)
if p2 is not None:
self.removeEvent(vSite, pk, p2)
min = findMinCircle(pi, pk, p2)
if min.point.getY() > vSite.point.getY():
vertexVerif(min)
self.addEvent(min)
else:
print("normal?")
......
......@@ -70,8 +70,23 @@ def computeBreakPoint(p1, p2, ly):
yb = (xb*xb - 2*x1*xb + h)/e
return [Vector3D(xa, ya), Vector3D(xb, yb)]
def createEdge(p0, p1):
vec = p1.point - p0.point
edge = Edge(Vector3D(-vec.getY(), vec.getX()))
p0.edges.append(edge)
p1.edges.append(edge)
def vertexVerif(min):
for i in range(len(min.sites)):
for j in range(i+1, len(min.sites)):
if min.sites[i].point.getX() > min.sites[j].point.getX():
min.sites[i], min.sites[j] = min.sites[j], min.sites[i]
if min.sites[1].point.getY() <= min.sites[0].point.getY() and min.sites[1].point.getY() <= min.sites[2].point.getY():
min.type = 0
elif min.sites[1].point.getY() > min.sites[0].point.getY() and min.sites[1].point.getY() > min.sites[2].point.getY():
min.type = 1
else:
min.type = 0
print("How to handle this thing?")
\ No newline at end of file
......@@ -31,12 +31,14 @@ class Node:
def remove(self, p0):
if p0.sites[1] is self.site:
pi = self.lastSite()
if pi in p0.sites:
pk = self.nextSite()
if pk in p0.sites:
p1 = pi.lastSite()
p2 = pk.nextSite()
piN = self.last()
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:
if self.root.root.left is self.root:
self.root.root.left = self.root.right
......@@ -52,11 +54,11 @@ class Node:
return [p1, pi, pk, p2]
if self.isLeaf():
assert(False), "No site found"
return [None, None, None, None]
#assert(False), "No site found"
return None
else:
l = self.left.remove(p0)
if l is not None:
if l is None:
return self.right.remove(p0)
else:
return l
......
......@@ -5,6 +5,8 @@ class VSite (Site):
def __init__(self, point, center):
Site.__init__(self, point)
self.center = center
self.type = 0
self.on = None
def __str__(self):
if len(self.sites) == 3:
......
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