Skip to content

Commit

Permalink
Added exception handling around resolution to distance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil A Smith committed Dec 3, 2019
1 parent 1231567 commit 505dc06
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions api/includes/pages/class.dc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,19 @@ function _norm_et($t, $e) {
# ------------------------------------------------------------------------
# Convert resolution to detector distance
function _r_to_dist($diam, $lambda, $r) {
if ($r == 0) return 0;
$result = 0;

$b=$lambda/(2*$r);
$d=2*asin($b);
$f=2*tan($d);

return number_format($diam/$f, 2);
try {
$b=$lambda/(2*$r);
$d=2*asin($b);
$f=2*tan($d);

$result = number_format($diam/$f, 2);
} catch (\Exception $e) {
error_log('Error converting resolution to distance, lambda=' . $lambda . ' r=' . $r . ' Exception: ' . $e->getMessage());
}

return $result;
}

# ------------------------------------------------------------------------
Expand Down

0 comments on commit 505dc06

Please sign in to comment.