diff --git a/plotters-backend/src/lib.rs b/plotters-backend/src/lib.rs index 93706bbd..0b35d1a3 100644 --- a/plotters-backend/src/lib.rs +++ b/plotters-backend/src/lib.rs @@ -233,8 +233,8 @@ pub trait DrawingBackend: Sized { .layout_box(text) .map_err(|e| DrawingErrorKind::FontError(Box::new(e)))?; let ((min_x, min_y), (max_x, max_y)) = layout; - let width = (max_x - min_x) as i32; - let height = (max_y - min_y) as i32; + let width = max_x - min_x; + let height = max_y - min_y; let dx = match style.anchor().h_pos { HPos::Left => 0, HPos::Right => -width, @@ -247,7 +247,7 @@ pub trait DrawingBackend: Sized { }; let trans = style.transform(); let (w, h) = self.get_size(); - match style.draw(text, (0, 0), |x, y, color| { + let drawing_result = style.draw(text, (0, 0), |x, y, color| { let (x, y) = trans.transform(x + dx - min_x, y + dy - min_y); let (x, y) = (pos.0 + x, pos.1 + y); if x >= 0 && x < w as i32 && y >= 0 && y < h as i32 { @@ -255,7 +255,8 @@ pub trait DrawingBackend: Sized { } else { Ok(()) } - }) { + }); + match drawing_result { Ok(drawing_result) => drawing_result, Err(font_error) => Err(DrawingErrorKind::FontError(Box::new(font_error))), } diff --git a/plotters-backend/src/rasterizer/circle.rs b/plotters-backend/src/rasterizer/circle.rs index fdc31b4e..fa7fc50d 100644 --- a/plotters-backend/src/rasterizer/circle.rs +++ b/plotters-backend/src/rasterizer/circle.rs @@ -168,7 +168,6 @@ fn draw_annulus( radius.0 as f64 - a0, a1.floor(), |h, (f, t)| { - let h = h as i32; let f = f as i32; let t = t as i32; check_result!(b.draw_line( diff --git a/plotters-backend/src/rasterizer/line.rs b/plotters-backend/src/rasterizer/line.rs index 17836d9d..ae1ddd4c 100644 --- a/plotters-backend/src/rasterizer/line.rs +++ b/plotters-backend/src/rasterizer/line.rs @@ -110,7 +110,7 @@ pub fn draw_line( } if to.0 > batch_limit && y < f64::from(to.1) { - let x = batch_limit as i32 + 1; + let x = batch_limit + 1; if 1.0 + y.floor() - y > 1e-5 { check_result!(put_pixel((x, y as i32), 1.0 + y.floor() - y)); } diff --git a/plotters-backend/src/rasterizer/path.rs b/plotters-backend/src/rasterizer/path.rs index 11a1d8ea..004461c2 100644 --- a/plotters-backend/src/rasterizer/path.rs +++ b/plotters-backend/src/rasterizer/path.rs @@ -145,8 +145,7 @@ pub fn polygonize(vertices: &[BackendCoord], stroke_width: u32) -> Vec Self { Pos { h_pos, v_pos } } - } } diff --git a/plotters-bitmap/src/bitmap/target.rs b/plotters-bitmap/src/bitmap/target.rs index b4dc210d..5384f4d3 100644 --- a/plotters-bitmap/src/bitmap/target.rs +++ b/plotters-bitmap/src/bitmap/target.rs @@ -24,7 +24,7 @@ impl<'a> Buffer<'a> { match self { #[cfg(all(not(target_arch = "wasm32"), feature = "image"))] Buffer::Owned(buf) => &mut buf[..], - Buffer::Borrowed(buf) => *buf, + Buffer::Borrowed(buf) => buf, } } } diff --git a/plotters-svg/src/svg.rs b/plotters-svg/src/svg.rs index 7ea105d3..6557fb04 100644 --- a/plotters-svg/src/svg.rs +++ b/plotters-svg/src/svg.rs @@ -17,11 +17,11 @@ use std::path::Path; fn make_svg_color(color: BackendColor) -> String { let (r, g, b) = color.rgb; - return format!("#{:02X}{:02X}{:02X}", r, g, b); + format!("#{:02X}{:02X}{:02X}", r, g, b) } fn make_svg_opacity(color: BackendColor) -> String { - return format!("{}", color.alpha); + format!("{}", color.alpha) } enum Target<'a> { diff --git a/plotters/src/coord/ranged1d/combinators/group_by.rs b/plotters/src/coord/ranged1d/combinators/group_by.rs index 7648f8e7..28e72ee4 100644 --- a/plotters/src/coord/ranged1d/combinators/group_by.rs +++ b/plotters/src/coord/ranged1d/combinators/group_by.rs @@ -85,8 +85,7 @@ impl Ranged for GroupBy { let outer_ticks = idx_iter; let outer_tick_size = interval * self.1; let inner_ticks_per_group = hint.max_num_points() / outer_ticks.len(); - let inner_ticks = - (outer_tick_size + inner_ticks_per_group - 1) / inner_ticks_per_group; + let inner_ticks = (outer_tick_size + inner_ticks_per_group - 1) / inner_ticks_per_group; let inner_ticks: Vec<_> = (0..(outer_tick_size / inner_ticks)) .map(move |x| x * inner_ticks) .collect(); diff --git a/plotters/src/coord/ranged1d/combinators/linspace.rs b/plotters/src/coord/ranged1d/combinators/linspace.rs index 85ff6c35..14b5ebaa 100644 --- a/plotters/src/coord/ranged1d/combinators/linspace.rs +++ b/plotters/src/coord/ranged1d/combinators/linspace.rs @@ -315,7 +315,7 @@ where } fn from_index(&self, idx: usize) -> Option { - self.grid_value.get(idx).map(Clone::clone) + self.grid_value.get(idx).cloned() } } diff --git a/plotters/src/coord/ranged1d/types/datetime.rs b/plotters/src/coord/ranged1d/types/datetime.rs index abd0a78b..62a0cce8 100644 --- a/plotters/src/coord/ranged1d/types/datetime.rs +++ b/plotters/src/coord/ranged1d/types/datetime.rs @@ -779,7 +779,7 @@ impl Ranged for RangedDuration { while current < self.1 { ret.push(current); - current = current + Duration::nanoseconds(period as i64); + current += Duration::nanoseconds(period as i64); } return ret; @@ -818,7 +818,7 @@ impl Ranged for RangedDuration { while current < self.1 { ret.push(current); - current = current + Duration::days(i64::from(days_per_tick)); + current += Duration::days(i64::from(days_per_tick)); } ret diff --git a/plotters/src/data/data_range.rs b/plotters/src/data/data_range.rs index 445260b9..3d42eec4 100644 --- a/plotters/src/data/data_range.rs +++ b/plotters/src/data/data_range.rs @@ -16,9 +16,9 @@ use num_traits::{One, Zero}; /// let range = fitting_range(&data); /// assert_eq!(range, std::ops::Range { start: -2, end: 14 }); /// ``` -pub fn fitting_range<'a, T: 'a, I: IntoIterator>(iter: I) -> Range +pub fn fitting_range<'a, T, I: IntoIterator>(iter: I) -> Range where - T: Zero + One + PartialOrd + Clone, + T: 'a + Zero + One + PartialOrd + Clone, { let (mut lb, mut ub) = (None, None); diff --git a/plotters/src/element/pie.rs b/plotters/src/element/pie.rs index cf61c63d..964fe959 100644 --- a/plotters/src/element/pie.rs +++ b/plotters/src/element/pie.rs @@ -79,7 +79,7 @@ impl<'a, Label: Display> Pie<'a, (i32, i32), Label> { self.start_radian = start_angle.to_radians(); } - /// + /// Set the label style. pub fn label_style>>(&mut self, label_style: T) { self.label_style = label_style.into(); } diff --git a/plotters/src/element/text.rs b/plotters/src/element/text.rs index a4382c01..e066fde4 100644 --- a/plotters/src/element/text.rs +++ b/plotters/src/element/text.rs @@ -116,8 +116,7 @@ impl<'a, Coord, T: Borrow> MultiLineText<'a, Coord, T> { } } - -// Rewrite of the layout function for multiline-text. It crashes when UTF-8 is used +// Rewrite of the layout function for multiline-text. It crashes when UTF-8 is used // instead of ASCII. Solution taken from: // https://stackoverflow.com/questions/68122526/splitting-a-utf-8-string-into-chunks // and modified for our purposes. @@ -132,7 +131,6 @@ fn layout_multiline_text<'a, F: FnMut(&'a str)>( func(line); } else { let mut indices = line.char_indices().map(|(idx, _)| idx).peekable(); - let font2 = font.clone(); let it = std::iter::from_fn(|| { let start_idx = match indices.next() { @@ -141,9 +139,9 @@ fn layout_multiline_text<'a, F: FnMut(&'a str)>( }; // iterate over indices - while let Some(idx) = indices.next() { + for idx in indices.by_ref() { let substring = &line[start_idx..idx]; - let width = font2.box_size(substring).unwrap_or((0, 0)).0 as i32; + let width = font.box_size(substring).unwrap_or((0, 0)).0 as i32; if width > max_width as i32 { break; } @@ -164,7 +162,9 @@ fn layout_multiline_text<'a, F: FnMut(&'a str)>( } } -#[cfg(feature = "ttf")] +// Only run the test on Linux because the default font is different +// on other platforms, causing different multiline splits. +#[cfg(all(feature = "ttf", target_os = "linux"))] #[test] fn test_multi_layout() { use plotters_backend::{FontFamily, FontStyle}; diff --git a/plotters/src/series/surface.rs b/plotters/src/series/surface.rs index 2307e32f..2621f4f1 100644 --- a/plotters/src/series/surface.rs +++ b/plotters/src/series/surface.rs @@ -213,7 +213,7 @@ where } else { self.vidx_1 += 1; self.vidx_2 = 1; - if let (Some(b0), Some(b1)) = (self.free_var_2.get(0), self.free_var_2.get(1)) { + if let (Some(b0), Some(b1)) = (self.free_var_2.first(), self.free_var_2.get(1)) { (b0, b1) } else { return None; diff --git a/plotters/src/style/font/ttf.rs b/plotters/src/style/font/ttf.rs index 57c02cf5..9029df55 100644 --- a/plotters/src/style/font/ttf.rs +++ b/plotters/src/style/font/ttf.rs @@ -124,7 +124,7 @@ fn load_font_data(face: FontFamily, style: FontStyle) -> FontResult { font_object_cache .borrow() .get(Borrow::::borrow(&key)) - .map(Clone::clone) + .cloned() }) { return Ok(font_object); }