Skip to content

Commit

Permalink
Add tests for edge collapsing
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Jan 2, 2025
1 parent c0f7bc8 commit cc0a1e6
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions test/simplification_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import pytest
import numpy as np
from zmsh.simplification import compute_plane
from zmsh.polytopal import (
standard_simplex,
join_vertices,
edge_collapse,
from_simplicial,
to_simplicial,
)


@pytest.mark.parametrize("dimension", [2, 3, 4])
Expand All @@ -15,3 +22,63 @@ def test_computing_planes(dimension):
ts /= np.sum(ts)
w = ts @ xs
assert np.abs(p[0] + np.dot(p[1:], w)) < 1e-6


def test_edge_collapse():
D_0 = np.ones((1, 5), dtype=np.int8)

D_1 = np.array(
[
[0, 0, 0, 0, -1, -1, -1, -1],
[-1, 0, 0, +1, +1, 0, 0, 0],
[+1, -1, 0, 0, 0, +1, 0, 0],
[0, +1, -1, 0, 0, 0, +1, 0],
[0, 0, +1, -1, 0, 0, 0, +1],
],
dtype=np.int8,
)

D_2 = np.array(
[
[+1, 0, 0, 0],
[0, +1, 0, 0],
[0, 0, +1, 0],
[0, 0, 0, +1],
[+1, 0, 0, -1],
[-1, +1, 0, 0],
[0, -1, +1, 0],
[0, 0, -1, +1],
],
dtype=np.int8,
)

Ds = [D_0, D_1, D_2]
vertex_ids = [1, 2]
Es = edge_collapse(Ds, vertex_ids)
simplices = to_simplicial(Es)
assert (vertex_ids[0] in simplices) and not (vertex_ids[1] in simplices)


def test_bunny_collapse():
patch = np.array(
[
[3, 5, 1],
[7, 5, 8],
[3, 8, 5],
[5, 7, 4],
[5, 4, 9],
[7, 3, 2],
[8, 3, 7],
[5, 9, 0],
[3, 1, 10],
[6, 3, 10],
[0, 1, 5],
[2, 3, 6],
],
)

Ds = from_simplicial(patch)
vertex_ids = [3, 5]
Es = edge_collapse(Ds, vertex_ids)
new_patch = to_simplicial(Es)
assert (vertex_ids[0] in new_patch) and not (vertex_ids[1] in new_patch)

0 comments on commit cc0a1e6

Please sign in to comment.