Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions surface_analyses/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def find_patches(faces, should_be_in_patch):
patches : list of np.ndarray objects.
Each array contains a list of vertex indices that define a patch.
"""
faces = np.asarray(faces)
should_be_in_patch = np.asarray(should_be_in_patch)
assert len(should_be_in_patch.shape) == 1
assert len(faces.shape) == 2 and faces.shape[1] == 3
n_vertices = should_be_in_patch.shape[0]
Expand Down
35 changes: 35 additions & 0 deletions test/patches_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
import numpy as np

import surface_analyses.surface as surf
import surface_analyses.patches as patches

@pytest.fixture
def minimal():
vertices = [[0., 0., 0.], [0., 0., 1.], [0., 1., 1.], [0., 2., 1.], [0., 2., 2.]]
faces = [[0, 1, 2], [2, 3, 4]]
s = surf.Surface(vertices, faces)
s.data['DATA'] = [-2, -1, 0, 1, 2]
return s

def test_finds_patches_full(minimal):
p = patches.find_patches(minimal.faces, [True, True, True, True, True])
assert len(p) == 1
assert np.all(p[0] == [0, 1, 2, 3, 4])

def test_finds_patches_separate(minimal):
p = patches.find_patches(minimal.faces, [True, True, False, True, True])
assert len(p) == 2
assert np.all(p[0] == [0, 1])
assert np.all(p[1] == [3, 4])
area = minimal.vertex_areas()
assert area[p[0]].sum() == 1.0

def test_finds_patches_separate(minimal):
p = patches.find_patches(minimal.faces, [True, True, False, True, True])
assert len(p) == 2
assert np.all(p[0] == [0, 1])
assert np.all(p[1] == [3, 4])
area = minimal.vertex_areas()
assert area[p[0]].sum() == pytest.approx(1/3)
assert area[p[1]].sum() == pytest.approx(1/3)
4 changes: 4 additions & 0 deletions test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ def test_ses_gisttools():
out = surf.compute_ses_gisttools(grid, [[0.0, 0.0, 0.0]], [1.0])
# area of a unit sphere is 4*pi = 12.566, but we are not really exact
assert np.isclose(out.areas().sum(), 12.5876)

def test_triangle_area(minimal):
areas = minimal.vertex_areas()
assert np.allclose(areas, [1/6, 1/6, 1/6])
Loading