Skip to content

Commit 7f71166

Browse files
authored
Provide better debug_asserts for ray intersections (emilk#5504)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> Title. This would have helped me debug bugs quicker. * [x] I have followed the instructions in the PR template
1 parent 27a5803 commit 7f71166

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/emath/src/rect.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,11 @@ impl Rect {
649649
///
650650
/// A ray that starts inside the rect will return `true`.
651651
pub fn intersects_ray(&self, o: Pos2, d: Vec2) -> bool {
652-
debug_assert!(d.is_normalized(), "expected normalized direction");
652+
debug_assert!(
653+
d.is_normalized(),
654+
"expected normalized direction, but `d` has length {}",
655+
d.length()
656+
);
653657

654658
let mut tmin = -f32::INFINITY;
655659
let mut tmax = f32::INFINITY;
@@ -677,7 +681,11 @@ impl Rect {
677681
///
678682
/// `d` is the direction of the ray and assumed to be normalized.
679683
pub fn intersects_ray_from_center(&self, d: Vec2) -> Pos2 {
680-
debug_assert!(d.is_normalized(), "expected normalized direction");
684+
debug_assert!(
685+
d.is_normalized(),
686+
"expected normalized direction, but `d` has length {}",
687+
d.length()
688+
);
681689

682690
let mut tmin = f32::NEG_INFINITY;
683691
let mut tmax = f32::INFINITY;

0 commit comments

Comments
 (0)