Skip to content

Commit f50a6c7

Browse files
committed
test: add tests for cotmatrix, grad, simplify, cut_mesh, face_components
1 parent 0241dee commit f50a6c7

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

tests/test_cotmatrix.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import compas
2+
from compas_libigl.cotmatrix import trimesh_cotmatrix, trimesh_cotmatrix_entries
3+
from compas.datastructures import Mesh
4+
5+
6+
def test_trimesh_cotmatrix():
7+
mesh = Mesh.from_off(compas.get("tubemesh.off"))
8+
mesh.quads_to_triangles()
9+
M = mesh.to_vertices_and_faces()
10+
L = trimesh_cotmatrix(M)
11+
# Cotmatrix is V x V sparse matrix
12+
assert L.shape[0] == mesh.number_of_vertices()
13+
assert L.shape[1] == mesh.number_of_vertices()
14+
15+
16+
def test_trimesh_cotmatrix_entries():
17+
mesh = Mesh.from_off(compas.get("tubemesh.off"))
18+
mesh.quads_to_triangles()
19+
M = mesh.to_vertices_and_faces()
20+
C = trimesh_cotmatrix_entries(M)
21+
# Cotmatrix entries is F x 3 (one cotan per edge per face)
22+
assert C.shape[0] == mesh.number_of_faces()
23+
assert C.shape[1] == 3

tests/test_grad.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import compas
2+
from compas_libigl.grad import trimesh_grad
3+
from compas.datastructures import Mesh
4+
5+
6+
def test_trimesh_grad():
7+
mesh = Mesh.from_off(compas.get("tubemesh.off"))
8+
mesh.quads_to_triangles()
9+
M = mesh.to_vertices_and_faces()
10+
G = trimesh_grad(M)
11+
# Gradient operator is (3*F) x V sparse matrix
12+
# When multiplied by V-length scalar field, produces 3F gradient components
13+
assert G.shape[0] == 3 * mesh.number_of_faces()
14+
assert G.shape[1] == mesh.number_of_vertices()

tests/test_meshing.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import compas
2-
from compas_libigl.meshing import trimesh_remesh_along_isoline, trimesh_remesh_along_isolines
2+
from compas_libigl.meshing import (
3+
trimesh_remesh_along_isoline,
4+
trimesh_remesh_along_isolines,
5+
trimesh_cut_mesh,
6+
trimesh_face_components,
7+
)
38
from compas.datastructures import Mesh
49

510

@@ -29,3 +34,27 @@ def test_trimesh_remesh_along_isolines():
2934
assert len(F2) > 0
3035
assert len(S2) == len(V2)
3136
assert len(G2) == len(F2)
37+
38+
39+
def test_trimesh_cut_mesh():
40+
mesh = Mesh.from_off(compas.get("tubemesh.off"))
41+
mesh.quads_to_triangles()
42+
M = mesh.to_vertices_and_faces()
43+
V, F = M
44+
# Create cut flags: all ones means cut all edges
45+
cuts = [[1, 1, 1] for _ in F]
46+
Vn, Fn = trimesh_cut_mesh(M, cuts)
47+
# After cutting all edges, we should have more vertices
48+
assert len(Vn) >= len(V)
49+
assert len(Fn) == len(F)
50+
51+
52+
def test_trimesh_face_components():
53+
mesh = Mesh.from_off(compas.get("tubemesh.off"))
54+
mesh.quads_to_triangles()
55+
M = mesh.to_vertices_and_faces()
56+
C = trimesh_face_components(M)
57+
# Component IDs, one per face
58+
assert len(C) == mesh.number_of_faces()
59+
# Connected mesh should have single component (component 0)
60+
assert max(C) == 0

tests/test_simplify.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from compas_libigl.simplify import ramer_douglas_peucker
2+
3+
4+
def test_ramer_douglas_peucker():
5+
# Simple polyline: a zigzag that can be simplified
6+
points = [
7+
[0.0, 0.0, 0.0],
8+
[1.0, 0.1, 0.0], # slightly off the line
9+
[2.0, 0.0, 0.0],
10+
[3.0, 0.05, 0.0], # slightly off the line
11+
[4.0, 0.0, 0.0],
12+
]
13+
# With high threshold, should simplify to just endpoints
14+
S, J, Q = ramer_douglas_peucker(points, threshold=0.5)
15+
assert len(S) <= len(points)
16+
assert len(S) >= 2 # At least start and end points
17+
# With zero threshold, should keep all points
18+
S2, J2, Q2 = ramer_douglas_peucker(points, threshold=0.0)
19+
assert len(S2) == len(points)
20+
21+
22+
def test_ramer_douglas_peucker_straight_line():
23+
# Perfectly straight line should simplify to 2 points
24+
points = [
25+
[0.0, 0.0, 0.0],
26+
[1.0, 0.0, 0.0],
27+
[2.0, 0.0, 0.0],
28+
[3.0, 0.0, 0.0],
29+
[4.0, 0.0, 0.0],
30+
]
31+
S, J, Q = ramer_douglas_peucker(points, threshold=0.01)
32+
assert len(S) == 2
33+
assert S[0] == [0.0, 0.0, 0.0]
34+
assert S[1] == [4.0, 0.0, 0.0]

0 commit comments

Comments
 (0)