Skip to content

Commit

Permalink
Add: catch division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
OberGue committed Nov 8, 2024
1 parent 2f3f2c5 commit c4490f8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions splinepy/helpme/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ def swept(

# projecting B_(i) onto the plane normal to e1
B.append(B[i] - _np.dot(B[i], e1) * e1)
if _np.linalg.norm(B[i + 1]) < _settings.TOLERANCE:
_log.warning(
f"Vector B[{i + 1}] is close to zero. Adjusting "
f"to avoid division by zero."
)
B[i + 1] += _settings.TOLERANCE
B[i + 1] /= _np.linalg.norm(B[i + 1])

# defining e2 and e3 vectors
Expand Down Expand Up @@ -478,6 +484,12 @@ def swept(
B_rec[i]
- _np.dot(B_rec[i], tang_collection[i]) * tang_collection[i]
)
if _np.linalg.norm(B_rec[i + 1]) < _settings.TOLERANCE:
_log.warning(
f"Vector B_rec[{i + 1}] is close to zero. Adjusting "
f"to avoid division by zero."
)
B_rec[i + 1] += _settings.TOLERANCE
B_rec[i + 1] /= _np.linalg.norm(B_rec[i + 1])
# middle point between B and B_rec
B_rec[i + 1] = (B[i + 1] + B_rec[i + 1]) * 0.5
Expand Down

0 comments on commit c4490f8

Please sign in to comment.