def test_offset_merge(self): notch = Polygon([Point(0, 0), Point(7, 0), Point(4, 4), Point(3, 4)]) parts = notch.offset(-(1.0 + 0.1)) self.assertEqual(len(parts.polygons), 1) self.assertEqual(len(parts.polygons[0].points), 3)
def test_offset_square(self): square = Polygon([Point(0, 0), Point(3, 0), Point(3, 3), Point(0, 3)]) parts = square.offset(-0.25) self.assertEqual( set(c for poly in parts.polygons for p in poly.points for c in (p.x, p.y)), set([0.25, 2.75]))
def test_outset(self): square = Polygon([Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0)]) self.assertEqual(list(square.offset(0.1).points), [ Point(-0.1, -0.1), Point(-0.1, 1.1), Point(1.1, 1.1), Point(1.1, -0.1) ])
def test_offset_split_notch(self): notch = Polygon( [Point(0, 0), Point(6, 0), Point(6, 5), Point(3, 1), Point(0, 5)]) parts = notch.offset(-(0.375 + 0.1)) self.assertEqual(len(parts.polygons), 2)
def test_offset_foot_double_merge(self): foot = Polygon([ Point(0, 0), Point(10, 0), Point(10, 1), Point(10, 10), Point(1, 10), Point(1, 2), Point(0, 1) ]) rect = foot.offset(-2) self.assertEqual(len(rect.polygons[0].points), 4)
def test_inset_local_merge(self): # the magic of 3-4-5 triangles... trapezoid = Polygon( [Point(0, 0), Point(9, 12), Point(9 + 5, 12), Point(9 + 5 + 9, 0)]) self.assertEqual( [p.round(4) for p in trapezoid.offset(-5).points], [Point(10 + 3, 5), Point(10, 5), Point(10 + (3 / 2), 5 + (4 / 2))])