Ejemplo n.º 1
0
    def test_getBoundingTriangle2D(self):

        T = Triangulation()

        for i in range(15):
            v1 = Vertex(
                Point(np.random.random() * 54,
                      np.random.random() * 100))
            v2 = Vertex(
                Point(np.random.random() * 54,
                      np.random.random() * 100))
            v3 = Vertex(
                Point(np.random.random() * 54,
                      np.random.random() * 100))

            T.addVertex(v1)
            T.addVertex(v2)
            T.addVertex(v3)

        triangle = T.getBoundingTriangle2D()

        for vert in T.getVerts():
            self.assertEqual(
                Triangulation.Orient2D(vert, triangle.getVert1(),
                                       triangle.getVert2()), True)
            self.assertEqual(
                Triangulation.Orient2D(vert, triangle.getVert2(),
                                       triangle.getVert3()), True)
            self.assertEqual(
                Triangulation.Orient2D(vert, triangle.getVert3(),
                                       triangle.getVert1()), True)

        return
Ejemplo n.º 2
0
    def test_Orient2D(self):

        # comprueba que funciona para el caso normal
        v1 = Vertex(Point(-1, 0))
        v2 = Vertex(Point(1, 0))
        v3 = Vertex(Point(0.5, 0.5))

        self.assertEqual(Triangulation.Orient2D(v1, v2, v3), True)
        self.assertEqual(Triangulation.Orient2D(v3, v2, v1), False)

        # comprueba que funciona para distancias muy pequeñas
        v4 = Vertex(Point(0.5, 0.5))
        v5 = Vertex(Point(0.5, 0.56))
        v6 = Vertex(Point(0.49, 0.5))

        self.assertEqual(Triangulation.Orient2D(v4, v5, v6), True)
        self.assertEqual(Triangulation.Orient2D(v6, v5, v4), False)

        self.assertRaises(AssertionError,
                          lambda: Triangulation.Orient2D(v6, v5, v6))
        self.assertRaises(AssertionError,
                          lambda: Triangulation.Orient2D(v1, v1, v6))

        # comprueba que metodo resulta cuando se tratan de puntos colineales
        v7 = Vertex(Point(-1, 0))
        v8 = Vertex(Point(0, 0))
        v9 = Vertex(Point(1, 0))

        self.assertEqual(Triangulation.Orient2D(v7, v8, v9), True)
        self.assertEqual(Triangulation.Orient2D(v9, v8, v7), True)

        return