Skip to content

Commit

Permalink
Fixup for #2609.
Browse files Browse the repository at this point in the history
Improves the floating point comparison with zero. The strategy is to use
a relative tolerance for the ratio `minor.mag/major.mag`.

The softening constant `1e-100` is chosen such that:
1. If `minor.mag == 0.0` then the ratio is always `0.0` and no division
   by zero occurs.
2. The value of `major.mag + 1e-100 == major.mag` for all biophysically
   sensible values of `major.mag`.

If both `minor.mag` and `major.mag` are zero as floating point number,
then check may fail to raise a exception.
  • Loading branch information
1uc committed Nov 15, 2023
1 parent bd9426d commit d52aacd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion share/lib/hoc/import3d/import3d_gui.hoc
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ proc contour2centroid() {local i, j, imax, imin, ok localobj mean, pts, d, max,
// minor is normal and in xy plane
minor = m.getcol(3-tobj.min_ind-tobj.max_ind)
minor.x[2] = 0
if (minor.mag == 0.) {
if (minor.mag / (major.mag + 1e-100) < 1e-6) {
execerror("Failed to compute soma centroid from contour.")
}
minor.div(minor.mag)
Expand Down

0 comments on commit d52aacd

Please sign in to comment.