Skip to content

Commit faef059

Browse files
committed
Add tests to functions isCollapseOk and isSplitOk
1 parent 9d36137 commit faef059

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

mesh_model/mesh_analysis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,12 @@ def isSplitOk(d: Dart) -> bool:
350350

351351

352352
def isCollapseOk(d: Dart) -> bool:
353+
353354
mesh = d.mesh
354-
_, d1, d11, d21, d211, n1, n2, _, _ = mesh.active_triangles(d)
355+
if d.get_beta(2) is None:
356+
return False
357+
else:
358+
_, d1, d11, d21, d211, n1, n2, _, _ = mesh.active_triangles(d)
355359

356360
d112 = d11.get_beta(2)
357361
d12 = d1.get_beta(2)

test_modules/test_mesh_analysis.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from mesh_model.mesh_struct.mesh_elements import Dart
55
import mesh_model.mesh_analysis as Mesh_analysis
66
from actions.triangular_actions import split_edge_ids
7+
from plots.mesh_plotter import plot_mesh
78

89
class TestMeshAnalysis(unittest.TestCase):
910

@@ -69,6 +70,26 @@ def test_isFlipOk(self):
6970
dart_to_test = Dart(cmap, 2)
7071
self.assertTrue(Mesh_analysis.isFlipOk(dart_to_test))
7172

73+
def test_isSplitOk(self):
74+
nodes = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [2.0, 0.0]]
75+
faces = [[0, 1, 2], [0, 2, 3], [1, 4, 2]]
76+
cmap = Mesh(nodes, faces)
77+
plot_mesh(cmap)
78+
dart_to_test = Dart(cmap, 0)
79+
self.assertFalse(Mesh_analysis.isSplitOk(dart_to_test))
80+
dart_to_test = Dart(cmap, 2)
81+
self.assertTrue(Mesh_analysis.isSplitOk(dart_to_test))
82+
83+
def test_isCollapseOk(self):
84+
nodes = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [2.0, 0.0]]
85+
faces = [[0, 1, 2], [0, 2, 3], [1, 4, 2]]
86+
cmap = Mesh(nodes, faces)
87+
plot_mesh(cmap)
88+
dart_to_test = Dart(cmap, 0)
89+
self.assertFalse(Mesh_analysis.isCollapseOk(dart_to_test))
90+
dart_to_test = Dart(cmap, 2)
91+
self.assertFalse(Mesh_analysis.isCollapseOk(dart_to_test))
92+
7293

7394
if __name__ == '__main__':
7495
unittest.main()

0 commit comments

Comments
 (0)