This commit is contained in:
Theelx 2026-06-20 18:23:49 -10:00 committed by GitHub
commit e3f617d173
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -773,7 +773,11 @@ def earclip_triangulation(verts: np.ndarray, ring_ends: list) -> list:
# Move the ring which j belongs to from the
# attached list to the detached list
new_ring = next(
(ring for ring in detached_rings if ring[0] <= j < ring[-1]), None
# ring[-1] is the last valid index in the ring so the upper bound needs
# to be inclusive. Otherwise, a connection point on a ring's final vertex
# doesn't match any ring and triggers "Could not find a ring to attach"
(ring for ring in detached_rings if ring[0] <= j <= ring[-1]),
None,
)
if new_ring is not None:
detached_rings.remove(new_ring)

View file

@ -122,3 +122,29 @@ def test_polar_coords():
np.testing.assert_array_equal(
np.round(spherical_to_cartesian(b), 4), np.array([0, 2, 0])
)
def test_triangulation_ring_connection():
verts = np.array(
[
# outer ring
[-2, -2, 0],
[2, -2, 0],
[2, 2, 0],
[-2, 2, 0],
# inner ring (hole)
[-0.5, -1.5, 0],
[-0.5, -0.5, 0],
[-1.5, -0.5, 0],
[-1.5, -1.5, 0],
],
dtype=float,
)
ring_ends = [4, 8]
triangulation = earclip_triangulation(verts, ring_ends)
assert len(triangulation) > 0
assert len(triangulation) % 3 == 0
assert min(triangulation) >= 0
assert max(triangulation) < len(verts)