Skip to content

Commit 0ebac33

Browse files
CopilotLicini
andcommitted
Add sphere volume test to verify accuracy
Co-authored-by: Licini <17893605+Licini@users.noreply.github.com>
1 parent 9c0c835 commit 0ebac33

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/compas/datastructures/test_mesh.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@ def test_normal():
10701070

10711071

10721072
def test_volume():
1073+
import math
1074+
10731075
# Test with a cube
10741076
mesh = Mesh.from_stl(compas.get("cube_binary.stl"))
10751077
volume = mesh.volume()
@@ -1089,6 +1091,14 @@ def test_volume():
10891091
assert volume is not None
10901092
assert volume > 0
10911093

1094+
# Test with a sphere approximation
1095+
sphere_mesh = Mesh.from_shape(Sphere(radius=1.0), u=32, v=32)
1096+
volume = sphere_mesh.volume()
1097+
assert volume is not None
1098+
expected_sphere_volume = (4.0/3.0) * math.pi * (1.0 ** 3)
1099+
# Allow for ~1% error due to discretization
1100+
assert TOL.is_close(volume, expected_sphere_volume, rtol=0.02)
1101+
10921102
# Test with an open mesh (should return None)
10931103
mesh = Mesh.from_obj(compas.get("faces.obj"))
10941104
volume = mesh.volume()

0 commit comments

Comments
 (0)