def test_popTriangle(self): triangle1 = Triangle(Vertex(Point(-1, 0)), Vertex(Point(1, 0)), Vertex(Point(0, 1))) triangle2 = Triangle(Vertex(Point(-1, 0)), Vertex(Point(1, 0)), Vertex(Point(0, -1))) Tr = Triangulation() Tr.addTriangle(triangle1) Tr.addTriangle(triangle2) # quitar triangulo con la misma direccion self.assertEqual(len(Tr.getTriangles()) == 2, True) self.assertEqual(Tr.popTriangle(triangle2), True) self.assertEqual(Tr.popTriangle(triangle2), False) self.assertEqual(len(Tr.getTriangles()) == 1, True) # quitar triangulo con distinta direccion pero mismos vertices self.assertEqual( Tr.popTriangle( Triangle(Vertex(Point(-1, 0)), Vertex(Point(1, 0)), Vertex(Point(0, 1)))), True) self.assertEqual(len(Tr.getTriangles()) == 0, True) return
def test_deleteTriangleThatContains(self): v1 = Vertex(Point(1, 2)) v2 = Vertex(Point(2, 2)) v3 = Vertex(Point(3, 1)) v4 = Vertex(Point(5, 5)) t1 = Triangle(v1, v2, v3) t2 = Triangle(v2, v3, v4) T = Triangulation() T.addTriangle(t1) T.addTriangle(t2) self.assertEqual( T.getTriangles() == [t1, t2] or T.getTriangles() == [t2, t1], True, "No entrega los triangulos que se le agregaron.") T.deleteTrianglesThatContain(v4) self.assertEqual(T.getTriangles() == [t1], True, "No elimina triangulo que contiene el vertice v4.") T.deleteTrianglesThatContain(v4) self.assertEqual( T.getTriangles() == [t1], True, "Elimina triangulos aun cuando ningun triangulo contiene el vertice." ) T.deleteTrianglesThatContain(v2) self.assertEqual(T.getTriangles() == [], True, "No esta eliminando los triangulos.") return
from Logic.Point import Point from Logic.Triangulation import Triangulation from Logic.Vertex import Vertex from Logic.Triangle import Triangle Nvertices = 50 T2 = Triangulation() verts = [] # Añadimos puntos al azar np.random.seed(12) for i in range(1, Nvertices): verts.append(Vertex(Point(np.random.random() * 1000, np.random.random() * 1000))) # iniciamos triangulacion T2.makeDelaunay(verts) # dibujamos el camino completo for triangle in T2.Lepp(T2.getTriangles()[-25])[0]: triangle.draw2D(show=False, width=2) # dibujamos primer triangulo para saber donde comenzamos T2.Lepp(T2.getTriangles()[-25])[0][0].draw2D(show=False, width=4) # dibujamos triangulacion T2.draw2D(lineWidth=0.5) T2.improveTriangleCentroid(T2.getTriangles()[-25]) T2.draw2D()
from Logic.Triangulation import Triangulation from Logic.Vertex import Vertex from Logic.Triangle import Triangle Nvertices = 50 T2 = Triangulation() verts = [] # Añadimos puntos al azar for i in range(1, Nvertices): # Puntos que se añaden son muy lejanos unos de otros, el error cobra importancia en estos casos. verts.append(Vertex(Point(-500, 0))) verts.append(Vertex(Point(500, 0))) verts.append(Vertex(Point(0, 1))) # iniciamos triangulacion T2.makeDelaunay(verts) # dibujamos el camino completo for triangle in T2.Lepp(T2.getTriangles()[-1]): triangle.draw2D(show=False, width=2) # dibujamos primer triangulo para saber donde comenzamos T2.Lepp(T2.getTriangles()[-1])[0].draw2D(show=False, width=4) # dibujamos triangulacion T2.draw2D(lineWidth=0.5) T2.improveTriangle(T2.getTriangles()[-1]) T2.draw2D()