Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Filippo Luca Ferretti <[email protected]>
  • Loading branch information
lorycontixd and flferretti committed Nov 15, 2024
1 parent 90451e8 commit 495b799
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions tests/test_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -66,28 +70,29 @@ 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
)
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
)
Expand Down

0 comments on commit 495b799

Please sign in to comment.