mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Merge ed7e082c6f into 0e83f4b09a
This commit is contained in:
commit
e3f617d173
2 changed files with 31 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue