Apply clippy lints (#278)

This commit is contained in:
TrueDoctor
2021-07-17 11:12:37 +02:00
committed by GitHub
parent d57bfb87ee
commit 4637cbf12b
10 changed files with 43 additions and 61 deletions

View File

@@ -105,9 +105,7 @@ impl Folder {
pub fn bounding_box(&self, transform: glam::DAffine2) -> Option<[DVec2; 2]> {
let mut layers_non_empty_bounding_boxes = self.layers.iter().filter_map(|layer| layer.bounding_box(transform * layer.transform, layer.style)).peekable();
if layers_non_empty_bounding_boxes.peek().is_none() {
return None;
}
layers_non_empty_bounding_boxes.peek()?;
let mut x_min = f64::MAX;
let mut y_min = f64::MAX;
@@ -128,7 +126,7 @@ impl Folder {
y_max = bounding_box_max.y
}
}
return Some([DVec2::new(x_min, y_min), DVec2::new(x_max, y_max)]);
Some([DVec2::new(x_min, y_min), DVec2::new(x_max, y_max)])
}
}

View File

@@ -11,14 +11,8 @@ use super::LayerData;
use serde::{Deserialize, Serialize};
use std::fmt::Write;
#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
pub struct Line {}
impl Line {
pub fn new() -> Line {
Line {}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize)]
pub struct Line;
impl LayerData for Line {
fn to_kurbo_path(&self, transform: glam::DAffine2, _style: style::PathStyle) -> kurbo::BezPath {

View File

@@ -135,7 +135,7 @@ impl Layer {
name: None,
data,
transform: glam::DAffine2::from_cols_array(&transform),
style: style,
style,
cache: String::new(),
cache_dirty: true,
}
@@ -171,7 +171,7 @@ impl Layer {
*svg += self.render();
}
pub fn to_kurbo_path(&mut self) -> BezPath {
pub fn to_kurbo_path(&self) -> BezPath {
self.data.to_kurbo_path(self.transform, self.style)
}
@@ -198,9 +198,8 @@ impl Layer {
}
pub fn render_as_folder(&mut self, svg: &mut String) {
match &mut self.data {
LayerDataTypes::Folder(f) => f.render(svg, self.transform, self.style),
_ => {}
if let LayerDataTypes::Folder(f) = &mut self.data {
f.render(svg, self.transform, self.style)
}
}
}

View File

@@ -11,14 +11,8 @@ use super::LayerData;
use serde::{Deserialize, Serialize};
use std::fmt::Write;
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Rect {}
impl Rect {
pub fn new() -> Rect {
Rect {}
}
}
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct Rect;
impl LayerData for Rect {
fn to_kurbo_path(&self, transform: glam::DAffine2, _style: style::PathStyle) -> kurbo::BezPath {

View File

@@ -31,9 +31,7 @@ impl LayerData for Shape {
let mut path = kurbo::BezPath::new();
let apothem_offset_angle = std::f64::consts::PI / (self.sides as f64);
let relative_points = (0..self.sides)
.map(|i| apothem_offset_angle * ((i * 2 + ((self.sides + 1) % 2)) as f64))
.map(|radians| unit_rotation(radians));
let relative_points = (0..self.sides).map(|i| apothem_offset_angle * ((i * 2 + ((self.sides + 1) % 2)) as f64)).map(unit_rotation);
let (mut min_x, mut min_y, mut max_x, mut max_y) = (f64::MAX, f64::MAX, f64::MIN, f64::MIN);
relative_points.clone().for_each(|p| {
@@ -52,7 +50,7 @@ impl LayerData for Shape {
}
})
.map(|p| DVec2::new(p.x / 2. + 0.5, p.y / 2. + 0.5))
.map(|unit| transform.transform_point2(unit.into()))
.map(|unit| transform.transform_point2(unit))
.map(|pos| kurbo::Point::new(pos.x, pos.y))
.enumerate()
.for_each(|(i, p)| {