Skip to content

Commit

Permalink
fix+test: ensure correct return type for 2d
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Feb 19, 2024
1 parent add8ee3 commit cdd91ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ def test_2d():
area = xs3d.cross_sectional_area(labels, [0,0], [-1,1], [1,1])
assert np.isclose(area, 3 * np.sqrt(2))

area = xs3d.cross_sectional_area(labels, [-1,0], [-1,1], [1,1])
assert area == 0

area = xs3d.cross_sectional_area(labels, [1,-1], [-1,1], [1,1])
assert area == 0

labels[1,1] = 0
area = xs3d.cross_sectional_area(labels, [1,1], [0,1], [1,1])
assert area == 0



6 changes: 3 additions & 3 deletions xs3d/twod.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ def cross_sectional_area_2d(
sx, sy = binimg.shape

if pos[0] >= sx or pos[0] < 0:
return 0.0
return [0.0, 0b00111111]

if pos[1] >= sy or pos[1] < 0:
return 0.0
return [0.0, 0b00111111]

if binimg[int(pos[0]), int(pos[1])] == False:
return 0.0
return [0.0, 0b00111111]

nhat = np.array([ -vec[1], vec[0] ], dtype=np.float32)
nhat = nhat / np.sqrt(nhat[0] ** 2 + nhat[1] ** 2)
Expand Down

0 comments on commit cdd91ca

Please sign in to comment.