Commit 3a57bd60 authored by ronan's avatar ronan
Browse files

Edges polygons fonctionnent

parent f4f94bd5
......@@ -18,27 +18,22 @@ class BeachLine:
return
self.root.update(ly)
def remove(self, p0):
def remove(self, p0, edges):
assert(self.root is not None)
a = self.root.remove(p0)
a = self.root.remove(p0, edges)
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[j].point.getX():
assert(False)
def removeFromVSite(self, vSite, edges):
if vSite.type == 1:
i = 0
while vSite.sites[i] is not vSite.on:
i+=1
i += 1
assert(i != 1)
vSite.sites[i] = vSite.sites[1]
vSite.sites[1] = vSite.on
return self.remove(vSite)
return self.remove(vSite, edges)
def draw(self, screen, x, y, sizeD):
if self.root is not None:
......
......@@ -22,10 +22,33 @@ class Edge:
else:
self.p0 = p
def draw(self, screen, fX = 1.0, fY = 1.0):
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:
if self.vec.getY() > self.vec.getX():
if self.p1.getY() > 0:
fac = self.p1.getY()/self.vec.getY()
x = self.p1.getX() + fac*self.vec.getX()
screen.create_line(self.p1.getX() * fX, self.p1.getY() * fY, x * fX, 0.0)
else:
if self.p1.getX() > 0:
fac = self.p1.getX()/self.vec.getX()
y = self.p1.getY() + fac*self.vec.getY()
screen.create_line(self.p1.getX() * fX, self.p1.getY() * fY, 0.0, y * fY)
if self.p1 is not None:
self.p1.drawF(screen, fX, fY, "Red")
\ No newline at end of file
self.p1.drawF(screen, fX, fY, "Red")
elif self.p0 is not None:
if self.vec.getY() > self.vec.getX():
if self.p0.getY() < maxY:
fac = (maxY - self.p0.getY())/self.vec.getY()
x = self.p0.getX() + fac*self.vec.getX()
screen.create_line(self.p0.getX() * fX, self.p0.getY() * fY, x * fX, maxY)
else:
if self.p0.getX() < maxX:
fac = (maxX - self.p0.getX())/self.vec.getX()
y = self.p0.getY() + fac*self.vec.getY()
screen.create_line(self.p0.getX() * fX, self.p0.getY() * fY, maxX, y * fY)
\ No newline at end of file
......@@ -89,7 +89,7 @@ class Fortune:
"""
self.rEvents.append(vSite)
[p1, pi, pk, p2] = self.beachLine.removeFromVSite(vSite)
[p1, pi, pk, p2] = self.beachLine.removeFromVSite(vSite, self.edges)
for i in range(len(vSite.sites)):
vSite.sites[i].sites.remove(vSite)
"""print("remove-> " + str(p1) + ", " + str(pi) + ", " + str(pk) + ", " + str(p2))
......
......@@ -31,28 +31,26 @@ class Node:
else:
return self.right.insert(p0, edges)
def remove(self, p0):
if self.site is not None and self.site.name == "p8":
pass
if p0.sites[1] is self.site:
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
self.eraseNode(p0)
def remove(self, p0, edges):
if p0.on is self.site:
piN = self.fullLast()
if piN[0].site in p0.sites:
pkN = self.fullNext()
if pkN[0].site in p0.sites:
p1 = piN[0].lastSite()
p2 = pkN[0].nextSite()
pi = piN[0].site
pk = pkN[0].site
self.eraseNode(p0, piN, pkN, edges)
return [p1, pi, pk, p2]
if self.isLeaf():
#assert(False), "No site found"
return None
else:
l = self.left.remove(p0)
l = self.left.remove(p0, edges)
if l is None:
return self.right.remove(p0)
return self.right.remove(p0, edges)
else:
return l
......@@ -81,6 +79,20 @@ class Node:
def isLeaf(self):
return self.left is None and self.right is None
def fullNext(self):
root = self.findRootRight()
if root is None:
return [None, None]
else:
return [root.right.low(), root]
def fullLast(self):
root = self.findRootLeft()
if root is None:
return [None, None]
else:
return [root.left.max(), root]
def next(self):
root = self.findRootRight()
if root is None:
......@@ -138,6 +150,10 @@ class Node:
return self.root.findRootLeft()
def split(self, p, edges):
# Création d'un nouveau edge
# Les points sont ordonnés selon X
# 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:
......@@ -163,8 +179,22 @@ class Node:
self.value = p.point.getY()
self.right.value = p.point.getY()
def eraseNode(self, p0):
def eraseNode(self, p0, piN, pkN, edges):
# On ajoute le point centre au root edge et au second root node
# On retire l'edge du node root
# On créer un nouveau edge pour remplacer l'edge du second root
# Ce nouvel edge démarre du point centre
self.root.edge.set(p0.center, self.root.p)
toModify = piN[1]
if self.root is toModify:
toModify = pkN[1]
toModify.edge.set(p0.center, toModify.p)
toModify.edge = createEdge(piN[0].site, pkN[0].site)
toModify.edge.set(p0.center, 0)
toModify.p = 1
edges.append(toModify.edge)
if self.root.left is self:
self.root.right.root = self.root.root
if self.root.root.left is self.root:
......
......@@ -67,11 +67,7 @@ def clavier(event):
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")
edges[i].draw(canvas, fac.getX(), fac.getY(), 20, 20)
"""
for i in range(len(fortune.sites)):
......@@ -108,7 +104,7 @@ if __name__ == "__main__":
vec.append(Vector3D(2, 1))
vec.append(Vector3D(4, 1.1))
vec.append(Vector3D(5, 2.7))
vec.append(Vector3D(3, 3))
vec.append(Vector3D(3.2, 3))
vec.append(Vector3D(4.2, 4))
vec.append(Vector3D(5.2, 5))
vec.append(Vector3D(3.1, 5.2))
......
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