From 3f056ed76ce7abadb447c0d0bb8ca5c75712ee23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20R=C3=B6ssler?= Date: Wed, 11 Mar 2020 13:04:10 +0100 Subject: [PATCH 1/4] avoid crash and provide a simple solution for very small log scales --- src/coord/logarithmic.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coord/logarithmic.rs b/src/coord/logarithmic.rs index 3cb50262..54e47181 100644 --- a/src/coord/logarithmic.rs +++ b/src/coord/logarithmic.rs @@ -92,6 +92,13 @@ impl Ranged for LogCoord { .log10() .abs() .floor() as usize; + if tier_1 == 0 { + let from = self.logic.start.as_f64().floor() as i32; + let to = self.logic.end.as_f64().ceil() as i32; + let mut ret = vec![]; + { from..=to }.for_each(|i| ret.push(V::from_f64(f64::from(i)))); + return ret; + } let tier_2_density = if max_points < tier_1 { 0 } else { From b6c798e8e892bb07f8494257bb61dedfce0ad555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20R=C3=B6ssler?= Date: Mon, 30 Mar 2020 18:12:07 +0200 Subject: [PATCH 2/4] respect max_points --- src/coord/logarithmic.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coord/logarithmic.rs b/src/coord/logarithmic.rs index 54e47181..c276c370 100644 --- a/src/coord/logarithmic.rs +++ b/src/coord/logarithmic.rs @@ -96,7 +96,9 @@ impl Ranged for LogCoord { let from = self.logic.start.as_f64().floor() as i32; let to = self.logic.end.as_f64().ceil() as i32; let mut ret = vec![]; - { from..=to }.for_each(|i| ret.push(V::from_f64(f64::from(i)))); + { from..=to } + .step_by(((to - from) / max_points).ceil()) + .for_each(|i| ret.push(V::from_f64(f64::from(i)))); return ret; } let tier_2_density = if max_points < tier_1 { From 67ea4a64567f2fc5f29cc1b24615d8de06503705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20R=C3=B6ssler?= Date: Mon, 30 Mar 2020 18:15:33 +0200 Subject: [PATCH 3/4] fix --- src/coord/logarithmic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coord/logarithmic.rs b/src/coord/logarithmic.rs index c276c370..b2927a15 100644 --- a/src/coord/logarithmic.rs +++ b/src/coord/logarithmic.rs @@ -97,7 +97,7 @@ impl Ranged for LogCoord { let to = self.logic.end.as_f64().ceil() as i32; let mut ret = vec![]; { from..=to } - .step_by(((to - from) / max_points).ceil()) + .step_by((f64::from(to - from) / f64::from(max_points)).ceil() as i32) .for_each(|i| ret.push(V::from_f64(f64::from(i)))); return ret; } From 869f6faee2a55e7d69daf04136484bee402ff3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20R=C3=B6ssler?= Date: Mon, 30 Mar 2020 18:20:47 +0200 Subject: [PATCH 4/4] fix --- src/coord/logarithmic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coord/logarithmic.rs b/src/coord/logarithmic.rs index b2927a15..038acf92 100644 --- a/src/coord/logarithmic.rs +++ b/src/coord/logarithmic.rs @@ -97,8 +97,8 @@ impl Ranged for LogCoord { let to = self.logic.end.as_f64().ceil() as i32; let mut ret = vec![]; { from..=to } - .step_by((f64::from(to - from) / f64::from(max_points)).ceil() as i32) - .for_each(|i| ret.push(V::from_f64(f64::from(i)))); + .step_by((f64::from(to - from) / f64::from(max_points as u32)).ceil() as usize) + .for_each(|i| ret.push(V::from_f64(f64::from(i)))); return ret; } let tier_2_density = if max_points < tier_1 {