Skip to content

Commit fb49e8d

Browse files
committed
More FP error cornor cases
1 parent 37d96f5 commit fb49e8d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

plotters/src/coord/ranged1d/types/numeric.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ macro_rules! gen_key_points_comp {
152152
}
153153
let new_right = range.1 - rem_euclid(range.1, old_scale / nxt);
154154

155-
let npoints = 1 + ((new_right - new_left) / old_scale * nxt) as usize;
155+
let npoints = 1.0 + ((new_right - new_left) / old_scale * nxt);
156156

157-
if npoints > max_points {
157+
if npoints.round() as usize > max_points {
158158
break 'outer;
159159
}
160160

@@ -431,5 +431,8 @@ mod test {
431431
let coord: RangedCoordf64 = (0.9995..1.0005).into();
432432
let points = coord.key_points(11);
433433
assert_eq!(points.len(), 11);
434+
let coord: RangedCoordf64 = (0.9995..1.0005).into();
435+
let points = coord.key_points(2);
436+
assert!(points.len() <= 2);
434437
}
435438
}

0 commit comments

Comments
 (0)