Skip to content

Commit

Permalink
Provide better debug_asserts for ray intersections
Browse files Browse the repository at this point in the history
  • Loading branch information
grtlr committed Dec 19, 2024
1 parent 8c4d8b2 commit 22218c1
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 22218c1

Please sign in to comment.