### Simplification

`Reste à corriger un cas`
parent bf7564c4
 ... ... @@ -20,6 +20,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 ... ... @@ -27,14 +29,6 @@ class BeachLine: return a def removeFromVSite(self, vSite, edges): 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, edges) def draw(self, screen, x, y, sizeD): ... ...
 ... ... @@ -49,73 +49,4 @@ 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: 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: 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: 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) """
 ... ... @@ -65,99 +65,75 @@ class Fortune: self.rEvents.append(site) [p1, p, p3] = self.beachLine.insert(site, self.edges) """print("=== Site Ev ===") """ print("=== Site Ev ===") print("Site = " + str(site)) print("insert-> " + str(p1) + ", " + str(p) + ", " + str(p3)) print("===============")""" print("===============") """ 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) pass self.removeEvent(p1, p, p3) # Création du segment # createEdge(p, site) # AJout des breakpoints if p1 is not None: min = findMinCircle(p1, p, site) if self.isValidVertex(min) and min.point.getY() >= site.point.getY(): min.on = p vertexVerif(min) self.addEvent(min) #Cas spécial if p3 is not None: min = findMinCircle(p3, p, site) if self.isValidVertex(min) and min.point.getY() >= site.point.getY(): min.on = p vertexVerif(min) self.addEvent(min) if p1 is p3: min = findMinCircle(p1, p, site) computeBreakPoint(p1, p, min.point.getY()) else: if p1 is not None: min = findMinCircle(p1, p, site) if self.isValidVertex(min) and min.point.getY() >= site.point.getY(): vertexVerif(min) self.addEvent(min) if p3 is not None: min = findMinCircle(site, p, p3) if self.isValidVertex(min) and min.point.getY() >= site.point.getY(): vertexVerif(min) self.addEvent(min) def handleVertex(self): vSite = self.events.pop(len(self.events)-1) on = None if vSite.type == 1: on = vSite.sites[0] if vSite.sites[0] is not vSite.on else vSite.sites[2] """print("=== Vertex Ev ===") """ 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, 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)) print("=================")""" """ print("remove-> " + str(p1) + ", " + str(pi) + ", " + str(pk) + ", " + str(p2)) print("=================") """ if pi is not None and pk is not None: #vSite.edges[0].addPoint(vSite.center) #vSite.edges[1].addPoint(vSite.center) #self.vertex.append(vSite.center) """ if vSite.type == 0: if not createEdgeIfNot(vSite.sites[0], vSite.sites[2]): print("Normal?") else: 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): if p1 is not None: # On supprime les evenements liés aux anciens points self.removeEvent(p1, pi, vSite) min = findMinCircle(p1, pi, pk) if self.isValidVertex(min) and min.point.getY() >= vSite.point.getY(): if vSite.type == 0: on = pi min.on = on vertexVerif(min) assert(min.type != 1 or vSite.type != 0), "Que faire?" assert(min.on is not None or min.type != 1) self.addEvent(min) if p2 is not None and (p2 is not vSite.on): if p2 is not None: # On supprime les evenements liés aux anciens points self.removeEvent(vSite, pk, p2) min = findMinCircle(pi, pk, p2) if self.isValidVertex(min) and min.point.getY() >= vSite.point.getY(): if vSite.type == 0: on = pk min.on = on vertexVerif(min) assert(min.type != 1 or vSite.type != 0), "Que faire?" assert(min.on is not None or min.type != 1) self.addEvent(min) else: print("normal?") ... ... @@ -183,12 +159,14 @@ class Fortune: @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 ... ... @@ -199,21 +177,20 @@ class Fortune: def removeEvent(self, p1, p, p3): i = 0 while i < len(p.sites): if p.sites[i] in p1.sites: if p.sites[i] in p3.sites: if p.sites[i] in self.events: self.events.remove(p.sites[i]) else: print("Nope") if p.sites[i].sites[1] is p: if p.sites[i].sites[0] is p1: if p.sites[i].sites[2] is p3: if p.sites[i] in self.events: self.events.remove(p.sites[i]) p1.sites.remove(p.sites[i]) p1.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 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 def isValidVertex(self, vSite): ... ...
 ... ... @@ -47,9 +47,9 @@ def findMinCircle(p1, p2, p3): def computeBreakPoint(p1, p2, ly): x1 = p1.point.getX(); x1_2 = x1*x1; x2 = p2.point.getX(); x2_2 = x2*x2; y1 = p1.point.getY(); y1_2 = y1*y1; y2 = p2.point.getY(); y2_2 = y2*y2; ly_2 = ly*ly; x1 = p1.point.getX(); x1_2 = x1*x1; x2 = p2.point.getX(); x2_2 = x2*x2 y1 = p1.point.getY(); y1_2 = y1*y1; y2 = p2.point.getY(); y2_2 = y2*y2 ly_2 = ly*ly # First part h = x1_2 + y1_2 - ly_2 ... ... @@ -142,72 +142,6 @@ def vertexVerif(min): min.sites[1].sites.append(min) min.sites[2].sites.append(min) # 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(): 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] i += 1 min.edges.append(edge) edge = None i = 0 while edge is None: if min.sites[2].edges[i] in min.sites[1].edges: 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(): 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] i += 1 min.edges.append(edge) # L'autre on cherche edge = None i = 0 # A régler while edge is None: if min.sites[1].edges[i] in min.on.edges: edge = min.sites[1].edges[i] i += 1 min.edges.append(edge) """ """ else: 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] i += 1 min.edges.append(edge) edge = None i = 0 while edge is None: if min.sites[2].edges[i] in min.sites[1].edges: edge = min.sites[2].edges[i] i += 1 min.edges.append(edge) """ def getPosCurve(p, x, y): a = p.getY()*p.getY() - y*y ... ...
 ... ... @@ -32,11 +32,11 @@ class Node: return self.right.insert(p0, edges) def remove(self, p0, edges): if p0.on is self.site: if p0.sites[1] is self.site: piN = self.fullLast() if piN[0] is not None and piN[0].site in p0.sites: if piN[0] is not None and piN[0].site is p0.sites[0]: pkN = self.fullNext() if pkN[0] is not None and pkN[0].site in p0.sites: if pkN[0] is not None and pkN[0].site is p0.sites[2]: p1 = piN[0].lastSite() p2 = pkN[0].nextSite() pi = piN[0].site ... ... @@ -45,7 +45,6 @@ class Node: return [p1, pi, pk, p2] if self.isLeaf(): #assert(False), "No site found" return None else: l = self.left.remove(p0, edges) ... ... @@ -151,11 +150,6 @@ class Node: 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,9 +198,7 @@ class Node: toModify.edge.test() 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.center, toModify.p) tP = toModify.p ... ... @@ -216,14 +208,12 @@ class Node: toModify.edge.test() toModify.edge = createEdge(piN[0].site, pkN[0].site) #toModify.edge.prec.append(lastEdge) toModify.edge.add(lastEdge, 0) lastEdge.add(toModify.edge, tP) toModify.edge.set(p0.center, 0) toModify.p = 1 edges.append(toModify.edge) lastEdge.test() self.root.edge.test() toModify.edge.test() ... ...
 ... ... @@ -5,8 +5,7 @@ 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: ... ...
 ... ... @@ -179,13 +179,17 @@ if __name__ == "__main__": vec.append(Vector3D(6.58333333, 1.1)) vec.append(Vector3D(6.1, 2)) vec.append(Vector3D(2.96666667, 1.01666667)) vec.append(Vector3D(4, 1)) vec.append(Vector3D(9.5, 2.06666667)) #vec.append(Vector3D(9.5, 2.06666667)) vec.append(Vector3D(11.41666667,3.61666667)) vec.append(Vector3D(6.6, 6.78333333)) vec.append(Vector3D(2.88333333, 6.08333333)) """ vec.append(Vector3D(5, 2.7)) vec.append(Vector3D(3.2, 3)) vec.append(Vector3D(4.2, 4)) ... ... @@ -194,7 +198,7 @@ if __name__ == "__main__": vec.append(Vector3D(1, 5)) vec.append(Vector3D(3, 8.2)) vec.append(Vector3D(1, 7)) """ start = [True] for i in vec: ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!