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
def test_getTriangleThatContain(self): T = Triangulation() v1 = Vertex(Point(-1, 0)) v2 = Vertex(Point(1, 0)) v3 = Vertex(Point(0, 1)) v4 = Vertex(Point(0, 0.5)) v5 = Vertex(Point(2, 2)) v6 = Vertex(Point(-1, 0)) v7 = Vertex(Point(1, 0)) v8 = Vertex(Point(0, -1)) v9 = Vertex(Point(0, 0)) triangle = Triangle(v1, v2, v3) triangle2 = Triangle(v6, v8, v7) triangle.setTriangle3(triangle2) triangle2.setTriangle2(triangle) T.addTriangle(triangle) T.addTriangle(triangle2) self.assertEqual(T.getTriangleThatContain(v4)[0], triangle) self.assertEqual(T.getTriangleThatContain(v5), []) self.assertEqual( T.getTriangleThatContain(v9)[0] == triangle or T.getTriangleThatContain(v9)[1] == triangle, True) self.assertEqual( T.getTriangleThatContain(v9)[0] == triangle2 or T.getTriangleThatContain(v9)[1] == triangle2, True) return
from Logic.Triangle import Triangle anguloMinimo = 30 T2 = Triangulation() # Añadimos puntos al azar t1 = Triangle(Vertex(Point(0, 0)), Vertex(Point(1000, 0)), Vertex(Point(1000, 100)), None, None, None) t2 = Triangle(Vertex(Point(0, 0)), Vertex(Point(1000, 100)), Vertex(Point(0, 100)), None, None, None) t1.setTriangle2(t2) t2.setTriangle3(t1) T2.addTriangle(t1) T2.addTriangle(t2) # mostramos la configuracion inicial T2.draw2D(lineWidth=0.5) # Mejoramos triangulacion mientras existan trianglos malos T2.mejorarTriangulos(angle=anguloMinimo, saveAnimation=True, whileTrue=True, dirImages="./img/", mostrar=False, verbose=True) #Mostramos la salida T2.draw2D()