From 756db671d67c1b70140051cfded46f2e1d34132b Mon Sep 17 00:00:00 2001 From: Lorenzo Conti <56968043+lorycontixd@users.noreply.github.com> Date: Fri, 15 Nov 2024 16:43:42 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Filippo Luca Ferretti <102977828+flferretti@users.noreply.github.com> --- tests/test_meshes.py | 51 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/tests/test_meshes.py b/tests/test_meshes.py index d38e958a5..a2b03982f 100644 --- a/tests/test_meshes.py +++ b/tests/test_meshes.py @@ -4,54 +4,58 @@ def test_mesh_wrapping_vertex_extraction(): - """Test the vertex extraction method on different meshes. + """ + Test the vertex extraction method on different meshes. 1. A simple box 2. A sphere """ - # Test 1: A simple box - # First, create a box with origin at (0,0,0) and extents (3,3,3) -> points span from -1.5 to 1.5 on axis + # Test 1: A simple box. + # First, create a box with origin at (0,0,0) and extents (3,3,3), + # i.e. points span from -1.5 to 1.5 on the axis. mesh = trimesh.creation.box( extents=[3.0, 3.0, 3.0], ) points = meshes.extract_points_vertices(mesh=mesh) assert len(points) == len(mesh.vertices) - # Test 2: A sphere - # The sphere is centered at the origin and has a radius of 1.0 + # Test 2: A sphere. + # The sphere is centered at the origin and has a radius of 1.0. mesh = trimesh.creation.icosphere(subdivisions=4, radius=1.0) points = meshes.extract_points_vertices(mesh=mesh) assert len(points) == len(mesh.vertices) def test_mesh_wrapping_aap(): - """Test the AAP wrapping method on different meshes. + """ + Test the AAP wrapping method on different meshes. 1. A simple box 1.1: Remove all points above x=0.0 1.2: Remove all points below y=0.0 2. A sphere """ - # Test 1.1: Remove all points above x=0.0 - # The expected result is that the number of points is halved - # First, create a box with origin at (0,0,0) and extents (3,3,3) -> points span from -1.5 to 1.5 on axis - mesh = trimesh.creation.box( - extents=[3.0, 3.0, 3.0], - ) + # Test 1.1: Remove all points above x=0.0. + # The expected result is that the number of points is halved. + # First, create a box with origin at (0,0,0) and extents (3,3,3), + # i.e. points span from -1.5 to 1.5 on the axis. + mesh = trimesh.creation.box(extents=[3.0, 3.0, 3.0]) points = meshes.extract_points_aap(mesh=mesh, axis="x", lower=0.0) assert len(points) == len(mesh.vertices) // 2 assert all(points[:, 0] > 0.0) - # Test 1.2: Remove all points below y=0.0 - # Again, the expected result is that the number of points is halved + # Test 1.2: Remove all points below y=0.0. + # The expected result is that the number of points is halved. points = meshes.extract_points_aap(mesh=mesh, axis="y", upper=0.0) assert len(points) == len(mesh.vertices) // 2 assert all(points[:, 1] < 0.0) - # Test 2: A sphere - # The sphere is centered at the origin and has a radius of 1.0. Points are expected to be halved + # Test 2: A sphere. + # The sphere is centered at the origin and has a radius of 1.0. + # Points are expected to be halved. mesh = trimesh.creation.icosphere(subdivisions=4, radius=1.0) - # Remove all points above y=0.0 + + # Remove all points above y=0.0. points = meshes.extract_points_aap(mesh=mesh, axis="y", lower=0.0) assert all(points[:, 1] >= 0.0) assert len(points) < len(mesh.vertices) @@ -66,8 +70,9 @@ def test_mesh_wrapping_points_over_axis(): 2. A sphere """ - # Test 1.1: Remove 10 points from the lower end of the x-axis - # First, create a box with origin at (0,0,0) and extents (3,3,3) -> points span from -1.5 to 1.5 on axis + # Test 1.1: Remove 10 points from the lower end of the x-axis. + # First, create a box with origin at (0,0,0) and extents (3,3,3), + # i.e. points span from -1.5 to 1.5 on the axis. mesh = trimesh.creation.box(extents=[3.0, 3.0, 3.0]) points = meshes.extract_points_select_points_over_axis( mesh=mesh, axis="x", direction="lower", n=4 @@ -75,19 +80,19 @@ def test_mesh_wrapping_points_over_axis(): assert len(points) == 4 assert all(points[:, 0] < 0.0) - # Test 1.2: Select 10 points from the higher end of the y-axis + # Test 1.2: Select 10 points from the higher end of the y-axis. points = meshes.extract_points_select_points_over_axis( mesh=mesh, axis="y", direction="higher", n=4 ) assert len(points) == 4 assert all(points[:, 1] > 0.0) - # Test 2: A sphere - # The sphere is centered at the origin and has a radius of 1.0 + # Test 2: A sphere. + # The sphere is centered at the origin and has a radius of 1.0. mesh = trimesh.creation.icosphere(subdivisions=4, radius=1.0) sphere_n_vertices = len(mesh.vertices) - # Select 10 points from the higher end of the z-axis + # Select 10 points from the higher end of the z-axis. points = meshes.extract_points_select_points_over_axis( mesh=mesh, axis="z", direction="higher", n=sphere_n_vertices // 2 )