From 95ba736d6653c54b5be6a689f858bc3eadd9f60c Mon Sep 17 00:00:00 2001 From: mtlcl410 <2368091+mtlcl410@users.noreply.github.com> Date: Mon, 2 Nov 2026 09:07:57 +0800 Subject: [PATCH] M5: a callout knee with a coordinate that isn't a number takes the bottom side whatever the other callout_side's doc says a coordinate that isn't a number takes the bottom side, but every comparison with NaN is false, so the other coordinate alone decided: [NaN, y above the box] gave Top, [x left of it, NaN] Left. A NaN coordinate is now checked before any comparison. Review on #4094 (CodeRabbit, crates/annot/src/create.rs). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv --- crates/annot/src/create.rs | 4 ++++ crates/annot/src/tests.rs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/annot/src/create.rs b/crates/annot/src/create.rs index 7b024479fb..86d01c23a6 100644 --- a/crates/annot/src/create.rs +++ b/crates/annot/src/create.rs @@ -231,6 +231,10 @@ impl Side { pub fn callout_side(rect: [f64; 4], knee: [f64; 2]) -> Side { let [x0, y0, x1, y1] = normalize(rect); let [x, y] = knee; + // Before any comparison: one with NaN is false, so the other coordinate alone would decide. + if x.is_nan() || y.is_nan() { + return Side::Bottom; + } if x < x0 { Side::Left } else if x > x1 { diff --git a/crates/annot/src/tests.rs b/crates/annot/src/tests.rs index ae4cc20099..074221aced 100644 --- a/crates/annot/src/tests.rs +++ b/crates/annot/src/tests.rs @@ -2470,7 +2470,7 @@ fn a_callouts_arrow_point_alone_keeps_its_knee() { #[test] fn a_callouts_knee_has_one_side_for_every_tie() { let tb = [100.0, 100.0, 200.0, 150.0]; - let cases: [([f64; 2], Side, &str); 26] = [ + let cases: [([f64; 2], Side, &str); 30] = [ ([100.004, 125.0], Side::Left, "on the left edge, give or take an f32"), ([199.996, 125.0], Side::Right, "on the right edge, give or take an f32"), ([150.0, 149.996], Side::Top, "on the top edge, give or take an f32"), @@ -2495,6 +2495,10 @@ fn a_callouts_knee_has_one_side_for_every_tie() { ([210.0, 90.0], Side::Right, "diagonally off the bottom-right corner"), ([f64::NAN, 125.0], Side::Bottom, "x not a number"), ([150.0, f64::NAN], Side::Bottom, "y not a number"), + ([f64::NAN, 160.0], Side::Bottom, "x not a number, y above the box"), + ([f64::NAN, 90.0], Side::Bottom, "x not a number, y below the box"), + ([90.0, f64::NAN], Side::Bottom, "y not a number, x left of the box"), + ([210.0, f64::NAN], Side::Bottom, "y not a number, x right of the box"), ([f64::NEG_INFINITY, 125.0], Side::Left, "infinitely far left"), ([150.0, f64::INFINITY], Side::Top, "infinitely far up"), ];