示例#1
0
    def test_origin_not_in_triangle(self):
        """

        """
        tri = Trigon((-175, 41), (-421, -714), (574, -645))
        assert Vuple((0, 0)) not in tri
        assert not tri.contains_origin()
示例#2
0
    def test_point_on_perimeter(self):
        """

        """
        pts = [(-340, 495), (-153, -910), (835, -947)]
        tri = Trigon.from_points(pts)
        assert tri.is_perimeter_point(pts[0])
示例#3
0
    def test_origin_in_triangle(self):
        """

        """
        pts = [(-340, 495), (-153, -910), (835, -947)]
        tri = Trigon.from_points(pts)
        assert (0, 0) in tri
        assert tri.contains_origin()
示例#4
0
def p102():
    # open file and put into list
    with open(r'../../txt_files/p102_triangles.txt') as f:
        triangles = [
            tuple(map(int, j.split(',')))
            for j in [i.strip('\n') for i in f.readlines()]
        ]
    # check if (0, 0) in triangle for triangle in the list
    return sum(1 for tri in triangles if (0, 0) in Trigon.from_points(tri))
示例#5
0
    def test_triangle_area_half(self):
        """

        """
        t2 = [(1, 0), (0, 1), (0, 0)]
        assert 0.5 == Trigon(*t2).area()