Skip to content

Commit e89a973

Browse files
committed
Fix compiler warnings and clippy lints
1 parent 8c7c370 commit e89a973

File tree

12 files changed

+54
-57
lines changed

12 files changed

+54
-57
lines changed

src/axis.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl TickSteps {
125125
let base_step_scale = 10f64.powf(power);
126126
BASE_STEPS
127127
.iter()
128-
.map(|&s| (s as f64 * base_step_scale))
128+
.map(|&s| (f64::from(s) * base_step_scale))
129129
.collect()
130130
}
131131
}
@@ -153,7 +153,7 @@ fn generate_ticks(min: f64, max: f64, step_size: f64) -> Vec<f64> {
153153
// standard spanning axis
154154
ticks.extend(
155155
(1..)
156-
.map(|n| -1.0 * n as f64 * step_size)
156+
.map(|n| -1.0 * f64::from(n) * step_size)
157157
.take_while(|&v| v >= min)
158158
.collect::<Vec<f64>>()
159159
.iter()
@@ -162,14 +162,14 @@ fn generate_ticks(min: f64, max: f64, step_size: f64) -> Vec<f64> {
162162
ticks.push(0.0);
163163
ticks.extend(
164164
(1..)
165-
.map(|n| n as f64 * step_size)
165+
.map(|n| f64::from(n) * step_size)
166166
.take_while(|&v| v <= max),
167167
);
168168
} else {
169169
// entirely negative axis
170170
ticks.extend(
171171
(1..)
172-
.map(|n| -1.0 * n as f64 * step_size)
172+
.map(|n| -1.0 * f64::from(n) * step_size)
173173
.skip_while(|&v| v > max)
174174
.take_while(|&v| v >= min)
175175
.collect::<Vec<f64>>()
@@ -181,7 +181,7 @@ fn generate_ticks(min: f64, max: f64, step_size: f64) -> Vec<f64> {
181181
// entirely positive axis
182182
ticks.extend(
183183
(1..)
184-
.map(|n| n as f64 * step_size)
184+
.map(|n| f64::from(n) * step_size)
185185
.skip_while(|&v| v < min)
186186
.take_while(|&v| v <= max),
187187
);

src/barchart.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ impl BarChart {
8989
&self.label
9090
}
9191

92-
fn get_value(&self) -> &f64 {
93-
&self.value
92+
fn get_value(&self) -> f64 {
93+
self.value
9494
}
9595
}
9696

@@ -125,10 +125,10 @@ impl CategoricalRepresentation for BarChart {
125125

126126
fn to_text(
127127
&self,
128-
x_axis: &axis::CategoricalAxis,
129-
y_axis: &axis::ContinuousAxis,
130-
face_width: u32,
131-
face_height: u32,
128+
_x_axis: &axis::CategoricalAxis,
129+
_y_axis: &axis::ContinuousAxis,
130+
_face_width: u32,
131+
_face_height: u32,
132132
) -> String {
133133
"".into()
134134
}

src/boxplot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ impl<'a> CategoricalRepresentation for BoxPlot<'a> {
149149

150150
fn to_text(
151151
&self,
152-
x_axis: &axis::CategoricalAxis,
153-
y_axis: &axis::ContinuousAxis,
154-
face_width: u32,
155-
face_height: u32,
152+
_x_axis: &axis::CategoricalAxis,
153+
_y_axis: &axis::ContinuousAxis,
154+
_face_width: u32,
155+
_face_height: u32,
156156
) -> String {
157157
"".into()
158158
}

src/function.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,8 @@ impl Style {
4141
self.colour = Some(v.clone())
4242
}
4343

44-
if let Some(ref v) = other.width {
45-
self.width = Some(v.clone())
46-
}
47-
48-
match other.width {
49-
Some(v) => self.width = Some(v),
50-
None => {}
44+
if let Some(v) = other.width {
45+
self.width = Some(v)
5146
}
5247
}
5348
}
@@ -90,7 +85,7 @@ impl Function {
9085
{
9186
let sampling = (upper - lower) / 200.;
9287
let samples = (0..)
93-
.map(|x| lower + (x as f64 * sampling))
88+
.map(|x| lower + (f64::from(x) * sampling))
9489
.take_while(|&x| x <= upper);
9590
let values = samples.map(|s| (s, f(s))).collect();
9691
Function {
@@ -157,10 +152,10 @@ impl ContinuousRepresentation for Function {
157152

158153
fn to_text(
159154
&self,
160-
x_axis: &axis::ContinuousAxis,
161-
y_axis: &axis::ContinuousAxis,
162-
face_width: u32,
163-
face_height: u32,
155+
_x_axis: &axis::ContinuousAxis,
156+
_y_axis: &axis::ContinuousAxis,
157+
_face_width: u32,
158+
_face_height: u32,
164159
) -> String {
165160
"".into()
166161
}

src/histogram.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ TODO:
2020
- What should be the default?
2121
*/
2222

23+
use std;
24+
2325
use svg;
2426

2527
use axis;
@@ -76,9 +78,9 @@ impl Histogram {
7678
let mut max = v.iter().fold(-1. / 0., |a, &b| f64::max(a, b));
7779
let mut min = v.iter().fold(1. / 0., |a, &b| f64::min(a, b));
7880

79-
if min == max {
80-
min = min - 0.5;
81-
max = max + 0.5;
81+
if (min - max).abs() < std::f64::EPSILON {
82+
min -= 0.5;
83+
max += 0.5;
8284
}
8385

8486
let mut bins = vec![0; num_bins];
@@ -111,7 +113,7 @@ impl Histogram {
111113
.unwrap();
112114
bins[bin] += 1;
113115
}
114-
let density_per_bin = bins.iter().map(|&x| x as f64 / bin_width).collect();
116+
let density_per_bin = bins.iter().map(|&x| f64::from(x) / bin_width).collect();
115117

116118
Histogram {
117119
bin_bounds: bounds,
@@ -134,7 +136,7 @@ impl Histogram {
134136

135137
fn y_range(&self) -> (f64, f64) {
136138
let max = *self.bin_counts.iter().max().unwrap();
137-
(0., max as f64)
139+
(0., f64::from(max))
138140
}
139141

140142
pub fn style(mut self, style: &Style) -> Self {

src/line.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Style {
4242
}
4343

4444
if let Some(ref v) = other.width {
45-
self.width = Some(v.clone())
45+
self.width = Some(*v)
4646
}
4747
}
4848
}
@@ -144,10 +144,10 @@ impl ContinuousRepresentation for Line {
144144

145145
fn to_text(
146146
&self,
147-
x_axis: &axis::ContinuousAxis,
148-
y_axis: &axis::ContinuousAxis,
149-
face_width: u32,
150-
face_height: u32,
147+
_x_axis: &axis::ContinuousAxis,
148+
_y_axis: &axis::ContinuousAxis,
149+
_face_width: u32,
150+
_face_height: u32,
151151
) -> String {
152152
"".into()
153153
}

src/page.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ impl<'a> Page<'a> {
5757

5858
let x_margin = 80;
5959
let y_margin = 60;
60-
let x_offset = 0.6 * x_margin as f64;
61-
let y_offset = 0.6 * y_margin as f64;
60+
let x_offset = 0.6 * f64::from(x_margin);
61+
let y_offset = 0.6 * f64::from(y_margin);
6262

6363
// TODO put multiple views in correct places
6464
for &view in &self.views {
6565
let view_group = view
66-
.to_svg((width - x_margin) as f64, (height - y_margin) as f64)?
66+
.to_svg(f64::from(width - x_margin), f64::from(height - y_margin))?
6767
.set(
6868
"transform",
69-
format!("translate({}, {})", x_offset, height as f64 - y_offset),
69+
format!("translate({}, {})", x_offset, f64::from(height) - y_offset),
7070
);
7171
document.append(view_group);
7272
}

src/scatter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl Style {
3838
self.colour = Some(v.clone())
3939
}
4040

41-
if let Some(ref v) = other.size {
42-
self.size = Some(v.clone())
41+
if let Some(v) = other.size {
42+
self.size = Some(v)
4343
}
4444
}
4545
}
@@ -98,7 +98,7 @@ impl Scatter {
9898
}
9999

100100
Scatter {
101-
data: data,
101+
data,
102102
style: Style::new(),
103103
}
104104
}

src/svg_render.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ where
174174
for &(x, y) in s {
175175
let x_pos = value_to_face_offset(x, x_axis, face_width);
176176
let y_pos = -value_to_face_offset(y, y_axis, face_height);
177-
let radius = style.get_size().clone().unwrap_or(5.) as f64;
177+
let radius = f64::from(style.get_size().clone().unwrap_or(5.));
178178
match style.get_marker().clone().unwrap_or(style::Marker::Circle) {
179179
style::Marker::Circle => {
180180
group.append(
@@ -241,7 +241,7 @@ where
241241
let l_pos = value_to_face_offset(l, x_axis, face_width);
242242
let u_pos = value_to_face_offset(u, x_axis, face_width);
243243
let width = u_pos - l_pos;
244-
let count_scaled = value_to_face_offset(count as f64, y_axis, face_height);
244+
let count_scaled = value_to_face_offset(f64::from(count), y_axis, face_height);
245245
let rect = node::element::Rectangle::new()
246246
.set("x", l_pos)
247247
.set("y", -count_scaled)
@@ -385,7 +385,7 @@ where
385385
}
386386

387387
pub fn draw_face_barchart<L, S>(
388-
d: &f64,
388+
d: f64,
389389
label: &L,
390390
x_axis: &axis::CategoricalAxis,
391391
y_axis: &axis::ContinuousAxis,
@@ -406,7 +406,7 @@ where
406406

407407
let box_width = space_per_tick / 2.;
408408

409-
let box_start = -value_to_face_offset(*d, y_axis, face_height);
409+
let box_start = -value_to_face_offset(d, y_axis, face_height);
410410
let box_end = -value_to_face_offset(0.0, y_axis, face_height);
411411

412412
group.append(

src/text_render.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ use std::collections::HashMap;
55

66
use axis;
77
use histogram;
8-
use scatter;
98
use style;
109
use utils::PairWise;
1110

1211
// Given a value like a tick label or a bin count,
1312
// calculate how far from the x-axis it should be plotted
1413
fn value_to_axis_cell_offset(value: f64, axis: &axis::ContinuousAxis, face_cells: u32) -> i32 {
15-
let data_per_cell = (axis.max() - axis.min()) / face_cells as f64;
14+
let data_per_cell = (axis.max() - axis.min()) / f64::from(face_cells);
1615
((value - axis.min()) / data_per_cell).round() as i32
1716
}
1817

@@ -123,7 +122,7 @@ fn create_x_axis_labels(x_tick_map: &HashMap<i32, f64>) -> Vec<XAxisLabel> {
123122
.iter()
124123
.map(|(&offset, &tick)| XAxisLabel {
125124
text: tick.to_string(),
126-
offset: offset,
125+
offset,
127126
}).collect();
128127
ls.sort_by_key(|l| l.offset);
129128
ls
@@ -288,7 +287,7 @@ pub fn render_face_bars(
288287
.map(|&bin| match bin {
289288
None => 0,
290289
Some(b) => {
291-
value_to_axis_cell_offset(h.bin_counts[b as usize] as f64, y_axis, face_height)
290+
value_to_axis_cell_offset(f64::from(h.bin_counts[b as usize]), y_axis, face_height)
292291
}
293292
}).collect();
294293

@@ -621,6 +620,7 @@ mod tests {
621620

622621
#[test]
623622
fn test_render_face_points() {
623+
use scatter;
624624
let data = vec![
625625
(-3.0, 2.3),
626626
(-1.6, 5.3),

0 commit comments

Comments
 (0)