Skip to content

Commit 3ebdc96

Browse files
committed
Bug fix: when f64 key points was fed 1..125, and ask for 12 key points, the algorithm does not emit the optimal choice
1 parent 12ba22a commit 3ebdc96

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ macro_rules! gen_key_points_comp {
141141
'outer: loop {
142142
let old_scale = scale;
143143
for nxt in [2.0, 5.0, 10.0].iter() {
144-
let mut new_left = range.0 - rem_euclid(range.0, scale / nxt);
144+
let mut new_left = range.0 - rem_euclid(range.0, old_scale / nxt);
145145
if new_left < range.0 {
146-
new_left += scale / nxt;
146+
new_left += old_scale / nxt;
147147
}
148-
let new_right = range.1 - rem_euclid(range.1, scale / nxt);
148+
let new_right = range.1 - rem_euclid(range.1, old_scale / nxt);
149149

150150
let npoints = 1 + ((new_right - new_left) / old_scale * nxt) as usize;
151151

@@ -420,5 +420,8 @@ mod test {
420420
let points = coord.key_points(6);
421421
assert_eq!(points.len(), 6);
422422
assert_eq!(points[0], 1.0);
423+
let coord: RangedCoordf64 = (1.0..125.0).into();
424+
let points = coord.key_points(12);
425+
assert_eq!(points.len(), 12);
423426
}
424427
}

0 commit comments

Comments
 (0)