def test_corner_case(self): a = LineSegment2(Point(10, 0), Point(0, 0)) b = LineSegment2(Point(5, 3), Point(5, 10)) line = CutLine.from_lines(a, b) self.assertEqual([(l.start, l.end) for l in line], [ ((0, Point(10.0, 5.0), 5.0), (0.2, Point(8.0, 3.0), 3.0)), ((0.2, Point(8.0, 3.0), 3.0), (0.2, Point(5.0, 1.5), 1.5)), ((0.2, Point(5.0, 1.5), 1.5), (0.5, Point(5.0, 1.5), 1.5)) ])
def test_pinch(self): simple = Polygon([ Point(4, 0), Point(0, 0), Point(1, 10), Point(2, 1), Point(3, 10) ]) segments = simple.segments() path = clearance(segments[0], segments[1:]) self.assertEqual(min([r for _, r in path if r > 0]), 0.5)
def test_fillet_square_inversion(self): points = [Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)] a = [ point.snap(1.0 / 256) for a, b, c in zip( points, [*points[1:], *points[:1]], [*points[2:], *points[:2]]) for point in list(shape.fillet(a, b, c, 0.25, segments=3)) ] points = list(reversed(points)) b = [ point.snap(1.0 / 256) for a, b, c in zip( points, [*points[1:], *points[:1]], [*points[2:], *points[:2]]) for point in list(shape.fillet(a, b, c, 0.25, segments=3)) ] self.assertEqual(set(a), set(b))
def test_angle(self): p = Point(1, 1) np = Vector(-1, 0) l = LineSegment2(Point(1, 0), Point(0, 0)) self.assertEqual(locate_circle(p, np, l), (Point(0, 1), 1, 1)) self.assertEqual(locate_circle(Point(1, 0), np, l), (Point(1, 0), 0, 0)) self.assertEqual(locate_circle(Point(-5, 0), np, l), None) self.assertEqual(locate_circle(Point(5, 0), np, l), None)
def test_parallel_lines(self): a = LineSegment2(Point(1, 0), Point(0, 0)) b = LineSegment2(Point(-2, 1), Point(2, 1)) line = CutLine.from_lines(a, b) self.assertEqual(line[0].start, (0, Point(1, 0.5), 0.5)) self.assertEqual(line[-1].end, (1, Point(0, 0.5), 0.5)) reversed = CutLine.from_lines(b, a) self.assertEqual(reversed[0].start, (0.5, Point(0, 0.5), 0.5)) self.assertEqual(reversed[-1].end, (0.75, Point(1, 0.5), 0.5))
def test_rounded_square(self): points = [Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)] actual = [ point.snap(0.125) for a, b, c in zip( points, [*points[1:], *points[:1]], [*points[2:], *points[:2]]) for point in list(shape.fillet(a, b, c, 0.25, segments=3)) ] expected = [ Point(0.75, 0.0), Point(0.875, 0.125), Point(1.0, 0.25), Point(1.0, 0.75), Point(0.875, 0.875), Point(0.75, 1.0), Point(0.25, 1.0), Point(0.125, 0.875), Point(0.0, 0.75), Point(0.0, 0.25), Point(0.125, 0.125), Point(0.25, 0.0) ] self.assertEqual(actual, expected)
def test_square_inputs(self): with self.assertRaises(AssertionError): shape.Rectangle(Point(0, 0, 0), Vector(1, 1)) shape.Rectangle(Point(0, 0), Vector(1, 1, 1))
def test_indent(self): segments = Polygon([ Point(0, 0), Point(0, 6), Point(2, 6), Point(2, 4), Point(1, 4), Point(1, 2), Point(2, 2), Point(2, 0) ]).segments() path = clearance(segments[0], segments[1:]) expected = [ (Point(0.0, 0.0), 0.0), (Point(0.5, 2.0), 0.5), (Point(0.5, 2.0), 0.5), (Point(0.5, 4.0), 0.5), (Point(0.5, 4.0), 0.5), (Point(0.0, 6.0), 0.0) ] self.assertEqual([(c.snap(0.25), round(r, 1)) for c, r in path], expected)