From 7f711668b483753b826c2fb2be09dc43966ab05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20G=C3=B6rtler?= Date: Thu, 19 Dec 2024 13:39:14 +0100 Subject: [PATCH] Provide better `debug_assert`s for ray intersections (#5504) Title. This would have helped me debug bugs quicker. * [x] I have followed the instructions in the PR template --- crates/emath/src/rect.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/emath/src/rect.rs b/crates/emath/src/rect.rs index 8b655bd722f..521b6f33f43 100644 --- a/crates/emath/src/rect.rs +++ b/crates/emath/src/rect.rs @@ -649,7 +649,11 @@ impl Rect { /// /// A ray that starts inside the rect will return `true`. pub fn intersects_ray(&self, o: Pos2, d: Vec2) -> bool { - debug_assert!(d.is_normalized(), "expected normalized direction"); + debug_assert!( + d.is_normalized(), + "expected normalized direction, but `d` has length {}", + d.length() + ); let mut tmin = -f32::INFINITY; let mut tmax = f32::INFINITY; @@ -677,7 +681,11 @@ impl Rect { /// /// `d` is the direction of the ray and assumed to be normalized. pub fn intersects_ray_from_center(&self, d: Vec2) -> Pos2 { - debug_assert!(d.is_normalized(), "expected normalized direction"); + debug_assert!( + d.is_normalized(), + "expected normalized direction, but `d` has length {}", + d.length() + ); let mut tmin = f32::NEG_INFINITY; let mut tmax = f32::INFINITY;