Skip to content

Commit

Permalink
Apply some clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronErhardt committed May 20, 2024
1 parent f29a6e3 commit 24bf063
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 30 deletions.
9 changes: 5 additions & 4 deletions plotters-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -247,15 +247,16 @@ 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 {
self.draw_pixel((x, y), color)
} else {
Ok(())
}
}) {
});
match drawing_result {
Ok(drawing_result) => drawing_result,
Err(font_error) => Err(DrawingErrorKind::FontError(Box::new(font_error))),
}
Expand Down
1 change: 0 additions & 1 deletion plotters-backend/src/rasterizer/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ fn draw_annulus<B: DrawingBackend, S: BackendStyle>(
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(
Expand Down
2 changes: 1 addition & 1 deletion plotters-backend/src/rasterizer/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn draw_line<DB: DrawingBackend, S: BackendStyle>(
}

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));
}
Expand Down
7 changes: 3 additions & 4 deletions plotters-backend/src/rasterizer/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ pub fn polygonize(vertices: &[BackendCoord], stroke_width: u32) -> Vec<BackendCo
}

#[cfg(test)]
mod test
{
mod test {
use super::*;

/// Test for regression with respect to https://github.com/plotters-rs/plotters/issues/562
Expand All @@ -168,6 +167,6 @@ mod test
compute_polygon_vertex(&path, 2.0, buf.as_mut());
assert!(!buf.is_empty());
let buf2 = vec![(18, 12)];
assert_eq!(buf,buf2);
assert_eq!(buf, buf2);
}
}
}
1 change: 0 additions & 1 deletion plotters-backend/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub mod text_anchor {
pub fn new(h_pos: HPos, v_pos: VPos) -> Self {
Pos { h_pos, v_pos }
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion plotters-bitmap/src/bitmap/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
4 changes: 2 additions & 2 deletions plotters-svg/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
3 changes: 1 addition & 2 deletions plotters/src/coord/ranged1d/combinators/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl<T: DiscreteRanged> Ranged for GroupBy<T> {
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();
Expand Down
2 changes: 1 addition & 1 deletion plotters/src/coord/ranged1d/combinators/linspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ where
}

fn from_index(&self, idx: usize) -> Option<T::ValueType> {
self.grid_value.get(idx).map(Clone::clone)
self.grid_value.get(idx).cloned()
}
}

Expand Down
4 changes: 2 additions & 2 deletions plotters/src/coord/ranged1d/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plotters/src/data/data_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &'a T>>(iter: I) -> Range<T>
pub fn fitting_range<'a, T, I: IntoIterator<Item = &'a T>>(iter: I) -> Range<T>
where
T: Zero + One + PartialOrd + Clone,
T: 'a + Zero + One + PartialOrd + Clone,
{
let (mut lb, mut ub) = (None, None);

Expand Down
2 changes: 1 addition & 1 deletion plotters/src/element/pie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<TextStyle<'a>>>(&mut self, label_style: T) {
self.label_style = label_style.into();
}
Expand Down
12 changes: 6 additions & 6 deletions plotters/src/element/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ impl<'a, Coord, T: Borrow<str>> 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.
Expand All @@ -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() {
Expand All @@ -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;
}
Expand All @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion plotters/src/series/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion plotters/src/style/font/ttf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn load_font_data(face: FontFamily, style: FontStyle) -> FontResult<FontExt> {
font_object_cache
.borrow()
.get(Borrow::<str>::borrow(&key))
.map(Clone::clone)
.cloned()
}) {
return Ok(font_object);
}
Expand Down

0 comments on commit 24bf063

Please sign in to comment.