From e6528bef3bd5f280f2e43e94999ed5bd723cb95c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 22 Apr 2025 12:37:40 +0200 Subject: [PATCH] Improve panic message Previously, computing the `sqrt` could have resulted in `NaN`, which would have lead to a generic panic in `Scalar` complaining about just that. --- experiments/2025-03-18/src/geometry/sketch.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/experiments/2025-03-18/src/geometry/sketch.rs b/experiments/2025-03-18/src/geometry/sketch.rs index 735517891..ec4c371e1 100644 --- a/experiments/2025-03-18/src/geometry/sketch.rs +++ b/experiments/2025-03-18/src/geometry/sketch.rs @@ -71,6 +71,16 @@ impl Sketch { let c = radius; let b_squared = c * c - a * a; + + if b_squared < Scalar::ZERO { + panic!( + "Radius of arc (`{radius}`) is too small: \ + Must be at least half the distance between \ + start (`{start:?}`) and end (`{end:?}`) \ + points, or the arc is not possible." + ); + } + b_squared.sqrt() };