Skip to content

Commit

Permalink
Provide better debug_asserts for ray intersections (emilk#5504)
Browse files Browse the repository at this point in the history
<!--
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
  • Loading branch information
grtlr authored Dec 19, 2024
1 parent 27a5803 commit 7f71166
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/emath/src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7f71166

Please sign in to comment.