예제 #1
0
 def test_line_cosine(self):
     """Test the line_cosine method."""
     points = np.array([[1, 1], [0, 0], [-1, 1], [0.8, 0.5]])
     ch = ConvexHull(points)
     self.assertTrue(np.allclose(ch.line_cosine(0, 1), math.cos(5*math.pi/4)))
     self.assertTrue(np.allclose(ch.line_cosine(0, 2), math.cos(math.pi)))
     self.assertTrue(np.allclose(ch.line_cosine(1, 3), math.cos(0.5585993153435626)))
예제 #2
0
    def test_point_distance(self):
        """Test the point_distance method."""
        p1 = np.array([0, 0])
        p2 = np.array([0, 7])
        self.assertEquals(ConvexHull.point_distance(p1, p2), 7)

        p1 = np.array([3.5, 7.4])
        p2 = np.array([-6, -9.2])
        self.assertEquals(ConvexHull.point_distance(p1, p2), 19.126160095534075)
예제 #3
0
    def test_is_right_turn(self):
        """Test the is_right_turn method."""
        points = np.array([[1, 1], [0, 0], [-1, 1], [0.8, 0.5]])
        ch = ConvexHull(points)
        ch.convex_hull = [1, 2]
        self.assertTrue(ch.is_right_turn(0))
        self.assertTrue(ch.is_right_turn(3))

        ch.convex_hull = [0, 1]
        self.assertTrue(ch.is_right_turn(2))
        self.assertFalse(ch.is_right_turn(3))

        ch.convex_hull = [1, 0]
        self.assertFalse(ch.is_right_turn(2))
        self.assertTrue(ch.is_right_turn(3))