Skip to content

Commit b054a80

Browse files
committed
clippy
1 parent 3887295 commit b054a80

File tree

12 files changed

+77
-54
lines changed

12 files changed

+77
-54
lines changed

src/chart/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
313313
/// - `y_spec`: The specification of Y axis
314314
/// - `z_sepc`: The specification of Z axis
315315
/// - Returns: A chart context
316+
#[allow(clippy::type_complexity)]
316317
pub fn build_cartesian_3d<X: AsRangedCoord, Y: AsRangedCoord, Z: AsRangedCoord>(
317318
&mut self,
318319
x_spec: X,

src/chart/context/cartesian3d/draw_impl.rs

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::cmp::Ordering;
2+
13
use plotters_backend::DrawingBackend;
24

35
use crate::chart::ChartContext;
@@ -44,6 +46,7 @@ where
4446
z_points,
4547
}
4648
}
49+
#[allow(clippy::type_complexity)]
4750
pub(crate) fn draw_axis_ticks(
4851
&mut self,
4952
axis: [[Coord3D<X::ValueType, Y::ValueType, Z::ValueType>; 3]; 2],
@@ -91,23 +94,27 @@ where
9194
for (pos, text) in labels {
9295
let logic_pos = Coord3D::build_coord([&pos[0], &pos[1], &pos[2]]);
9396
let mut font = font.clone();
94-
if dir.0 < 0 {
95-
font.pos = Pos::new(HPos::Right, VPos::Center);
96-
} else if dir.0 > 0 {
97-
font.pos = Pos::new(HPos::Left, VPos::Center);
98-
};
99-
if dir.1 < 0 {
100-
font.pos = Pos::new(HPos::Center, VPos::Bottom);
101-
} else if dir.1 > 0 {
102-
font.pos = Pos::new(HPos::Center, VPos::Top);
103-
};
97+
98+
match dir.0.cmp(&0) {
99+
Ordering::Less => font.pos = Pos::new(HPos::Right, VPos::Center),
100+
Ordering::Greater => font.pos = Pos::new(HPos::Left, VPos::Center),
101+
_ => (),
102+
}
103+
104+
match dir.1.cmp(&0) {
105+
Ordering::Less => font.pos = Pos::new(HPos::Center, VPos::Bottom),
106+
Ordering::Greater => font.pos = Pos::new(HPos::Center, VPos::Top),
107+
_ => (),
108+
}
109+
104110
let element = EmptyElement::at(logic_pos)
105111
+ PathElement::new(vec![(0, 0), dir], style.clone())
106112
+ Text::new(text.to_string(), (dir.0 * 2, dir.1 * 2), font.clone());
107113
self.plotting_area().draw(&element)?;
108114
}
109115
Ok(())
110116
}
117+
#[allow(clippy::type_complexity)]
111118
pub(crate) fn draw_axis(
112119
&mut self,
113120
idx: usize,
@@ -164,14 +171,16 @@ where
164171

165172
self.plotting_area().draw(&PathElement::new(
166173
vec![Coord3D::build_coord(start), Coord3D::build_coord(end)],
167-
style.clone(),
174+
style,
168175
))?;
169176

170177
Ok([
171178
[start[0].clone(), start[1].clone(), start[2].clone()],
172179
[end[0].clone(), end[1].clone(), end[2].clone()],
173180
])
174181
}
182+
183+
#[allow(clippy::type_complexity)]
175184
pub(crate) fn draw_axis_panels(
176185
&mut self,
177186
bold_points: &KeyPoints3d<X, Y, Z>,
@@ -199,6 +208,7 @@ where
199208
r_iter.next().unwrap()?,
200209
])
201210
}
211+
#[allow(clippy::type_complexity)]
202212
fn draw_axis_panel(
203213
&mut self,
204214
idx: usize,
@@ -223,40 +233,45 @@ where
223233
];
224234

225235
let (mut panel, start, end) = {
226-
let a = [&ranges[0][0], &ranges[1][0], &ranges[2][0]];
227-
let mut b = [&ranges[0][1], &ranges[1][1], &ranges[2][1]];
228-
let mut c = a;
229-
let d = b;
236+
let vert_a = [&ranges[0][0], &ranges[1][0], &ranges[2][0]];
237+
let mut vert_b = [&ranges[0][1], &ranges[1][1], &ranges[2][1]];
238+
let mut vert_c = vert_a;
239+
let vert_d = vert_b;
230240

231-
b[idx] = &ranges[idx][0];
232-
c[idx] = &ranges[idx][1];
241+
vert_b[idx] = &ranges[idx][0];
242+
vert_c[idx] = &ranges[idx][1];
233243

234-
let (a, b) = if coord.projected_depth(a[0].get_x(), a[1].get_y(), a[2].get_z())
235-
>= coord.projected_depth(c[0].get_x(), c[1].get_y(), c[2].get_z())
236-
{
237-
(a, b)
238-
} else {
239-
(c, d)
240-
};
244+
let (vert_a, vert_b) =
245+
if coord.projected_depth(vert_a[0].get_x(), vert_a[1].get_y(), vert_a[2].get_z())
246+
>= coord.projected_depth(
247+
vert_c[0].get_x(),
248+
vert_c[1].get_y(),
249+
vert_c[2].get_z(),
250+
)
251+
{
252+
(vert_a, vert_b)
253+
} else {
254+
(vert_c, vert_d)
255+
};
241256

242-
let mut m = a.clone();
243-
m[(idx + 1) % 3] = b[(idx + 1) % 3];
244-
let mut n = a.clone();
245-
n[(idx + 2) % 3] = b[(idx + 2) % 3];
257+
let mut m = vert_a;
258+
m[(idx + 1) % 3] = vert_b[(idx + 1) % 3];
259+
let mut n = vert_a;
260+
n[(idx + 2) % 3] = vert_b[(idx + 2) % 3];
246261

247262
(
248263
vec![
249-
Coord3D::build_coord(a),
264+
Coord3D::build_coord(vert_a),
250265
Coord3D::build_coord(m),
251-
Coord3D::build_coord(b),
266+
Coord3D::build_coord(vert_b),
252267
Coord3D::build_coord(n),
253268
],
254-
a,
255-
b,
269+
vert_a,
270+
vert_b,
256271
)
257272
};
258273
self.plotting_area()
259-
.draw(&Polygon::new(panel.clone(), panel_style.clone()))?;
274+
.draw(&Polygon::new(panel.clone(), panel_style))?;
260275
panel.push(panel[0].clone());
261276
self.plotting_area()
262277
.draw(&PathElement::new(panel, bold_grid_style.clone()))?;

src/chart/series.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'b, DB: DrawingBackend + 'a, CT: CoordTranslate> SeriesLabelStyle<'a, '
187187
let label_text = anno.get_label();
188188
let draw_func = anno.get_draw_func();
189189

190-
if label_text == "" && draw_func.is_none() {
190+
if label_text.is_empty() && draw_func.is_none() {
191191
continue;
192192
}
193193

src/coord/ranged1d/combinators/ckps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ where
156156
WithKeyPointMethod {
157157
inner: self.into(),
158158
bold_func: Box::new(func),
159-
light_func: Box::new(|_| vec![]),
159+
light_func: Box::new(|_| Vec::new()),
160160
}
161161
}
162162
}

src/coord/ranged1d/combinators/logarithmic.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ impl<V: LogScalable> From<LogRangeExt<V>> for LogCoord<V> {
126126
if start == 0.0 {
127127
start = start.max(end * 1e-5);
128128
}
129-
} else {
130-
if end == 0.0 {
131-
end = end.max(start * 1e-5);
132-
}
129+
} else if end == 0.0 {
130+
end = end.max(start * 1e-5);
133131
}
132+
134133
LogCoord {
135134
linear: (start.ln()..end.ln()).into(),
136135
logic: spec.range,
@@ -179,7 +178,7 @@ impl<V: LogScalable> LogCoord<V> {
179178
let a = V::from_f64(fv + self.zero_point);
180179
let b = V::from_f64(self.zero_point);
181180

182-
V::as_f64(&a) == V::as_f64(&b)
181+
(V::as_f64(&a) - V::as_f64(&b)).abs() < f64::EPSILON
183182
}
184183
}
185184

src/coord/ranged1d/types/numeric.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ macro_rules! gen_key_points_comp {
113113

114114
assert!(!(range.0.is_nan() || range.1.is_nan()));
115115

116-
if range.0 == range.1 {
116+
if (range.0 - range.1).abs() < f64::EPSILON {
117117
return vec![range.0 as $type];
118118
}
119119

src/coord/ranged3d/projection.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl ProjectionMatrix {
9292
])
9393
}
9494
/// Returns the matrix which rotates the coordinate
95+
#[allow(clippy::many_single_char_names)]
9596
pub fn rotate(x: f64, y: f64, z: f64) -> Self {
9697
let (c, b, a) = (x, y, z);
9798
ProjectionMatrix([
@@ -148,8 +149,8 @@ pub struct ProjectionMatrixBuilder {
148149
pivot_after: (i32, i32),
149150
}
150151

151-
impl ProjectionMatrixBuilder {
152-
pub fn new() -> Self {
152+
impl Default for ProjectionMatrixBuilder {
153+
fn default() -> Self {
153154
Self {
154155
yaw: 0.5,
155156
pitch: 0.15,
@@ -158,6 +159,12 @@ impl ProjectionMatrixBuilder {
158159
pivot_before: (0, 0, 0),
159160
}
160161
}
162+
}
163+
164+
impl ProjectionMatrixBuilder {
165+
pub fn new() -> Self {
166+
Self::default()
167+
}
161168

162169
/// Set the pivot point, which means the 3D coordinate "before" should be mapped into
163170
/// the 2D coordinatet "after"

src/data/float.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn find_minimal_repr(n: f64, eps: f64) -> (f64, usize) {
1313
}
1414
}
1515

16+
#[allow(clippy::never_loop)]
1617
fn float_to_string(n: f64, max_precision: usize, min_decimal: usize) -> String {
1718
let (mut result, mut count) = loop {
1819
let (sign, n) = if n < 0.0 { ("-", -n) } else { ("", n) };

src/drawing/area.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Rect {
5252
}
5353

5454
/// Evenly split the rectangle to a row * col mesh
55-
fn split_evenly<'a>(&'a self, (row, col): (usize, usize)) -> impl Iterator<Item = Rect> + 'a {
55+
fn split_evenly(&self, (row, col): (usize, usize)) -> impl Iterator<Item = Rect> + '_ {
5656
fn compute_evenly_split(from: i32, to: i32, n: usize, idx: usize) -> i32 {
5757
let size = (to - from) as usize;
5858
from + idx as i32 * (size / n) as i32 + idx.min(size % n) as i32
@@ -78,8 +78,8 @@ impl Rect {
7878
xs.extend(x_breaks.map(|v| v + self.x0));
7979
ys.extend(y_breaks.map(|v| v + self.y0));
8080

81-
xs.sort();
82-
ys.sort();
81+
xs.sort_unstable();
82+
ys.sort_unstable();
8383

8484
let xsegs: Vec<_> = xs
8585
.iter()

src/element/basic_shapes_3d.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Cubiod<X, Y, Z> {
99
}
1010

1111
impl<X: Clone, Y: Clone, Z: Clone> Cubiod<X, Y, Z> {
12+
#[allow(clippy::redundant_clone)]
1213
pub fn new<FS: Into<ShapeStyle>, ES: Into<ShapeStyle>>(
1314
[(x0, y0, z0), (x1, y1, z1)]: [(X, Y, Z); 2],
1415
face_style: FS,
@@ -50,7 +51,7 @@ impl<X, Y, Z, DB: DrawingBackend> Drawable<DB, BackendCoordAndZ> for Cubiod<X, Y
5051
) -> Result<(), DrawingErrorKind<DB::ErrorType>> {
5152
let vert: Vec<_> = points.collect();
5253
let mut polygon = vec![];
53-
for mask in vec![1, 2, 4] {
54+
for mask in [1, 2, 4].iter().cloned() {
5455
let mask_a = if mask == 4 { 1 } else { mask * 2 };
5556
let mask_b = if mask == 1 { 4 } else { mask / 2 };
5657
let a = 0;

src/series/surface.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub trait Direction<X, Y, Z> {
2020

2121
macro_rules! define_panel_descriptor {
2222
($name: ident, $var1: ident, $var2: ident, $out: ident, ($first: ident, $second:ident) -> $result: ident = $output: expr) => {
23+
#[allow(clippy::upper_case_acronyms)]
2324
pub struct $name;
2425
impl<X, Y, Z> Direction<X, Y, Z> for $name {
2526
type Input1Type = $var1;
@@ -175,11 +176,9 @@ where
175176
(self.surface_f)(a1.clone(), b0.clone()),
176177
),
177178
];
178-
return Some(Polygon::new(vert, style));
179-
}
180-
_ => {
181-
return None;
179+
Some(Polygon::new(vert, style))
182180
}
181+
_ => None,
183182
}
184183
}
185184
}

src/style/text.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ impl<'a, F: Into<FontFamily<'a>>, T: SizeDesc, C: Color> IntoTextStyle<'a>
190190
}
191191

192192
/// Make sure that we are able to automatically copy the `TextStyle`
193-
impl<'a, 'b: 'a> Into<TextStyle<'a>> for &'b TextStyle<'a> {
194-
fn into(self) -> TextStyle<'a> {
195-
self.clone()
193+
impl<'a, 'b: 'a> From<&'b TextStyle<'a>> for TextStyle<'a> {
194+
fn from(this: &'b TextStyle<'a>) -> Self {
195+
this.clone()
196196
}
197197
}
198198

0 commit comments

Comments
 (0)