mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-18 10:09:20 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
This commit is contained in:
1 parent
9d38c80b8a
commit
95ba736d66
2 files changed
+9
-1
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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"),
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user