mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
Apply clippy lints (#278)
This commit is contained in:
@@ -67,7 +67,6 @@ impl Document {
|
||||
/// Checks whether each layer under `path` intersects with the provided `quad` and adds all intersection layers as paths to `intersections`.
|
||||
pub fn intersects_quad(&self, quad: [DVec2; 4], path: &mut Vec<LayerId>, intersections: &mut Vec<Vec<LayerId>>) {
|
||||
self.document_folder(path).unwrap().intersects_quad(quad, path, intersections);
|
||||
return;
|
||||
}
|
||||
|
||||
/// Checks whether each layer under the root path intersects with the provided `quad` and returns the paths to all intersecting layers.
|
||||
@@ -229,7 +228,7 @@ impl Document {
|
||||
|
||||
pub fn layer_axis_aligned_bounding_box(&self, path: &[LayerId]) -> Result<Option<[DVec2; 2]>, DocumentError> {
|
||||
// TODO: Replace with functions of the transform api
|
||||
if let &[] = path {
|
||||
if path.is_empty() {
|
||||
// Special case for root. Root's local is the documents global, so we avoid transforming its transform by itself.
|
||||
self.layer_local_bounding_box(path)
|
||||
} else {
|
||||
@@ -265,13 +264,13 @@ impl Document {
|
||||
Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::SelectLayer { path }])
|
||||
}
|
||||
Operation::AddRect { path, insert_index, transform, style } => {
|
||||
let id = self.add_layer(&path, Layer::new(LayerDataTypes::Rect(Rect::new()), *transform, *style), *insert_index)?;
|
||||
let id = self.add_layer(&path, Layer::new(LayerDataTypes::Rect(Rect), *transform, *style), *insert_index)?;
|
||||
let path = [path.clone(), vec![id]].concat();
|
||||
|
||||
Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::SelectLayer { path }])
|
||||
}
|
||||
Operation::AddLine { path, insert_index, transform, style } => {
|
||||
let id = self.add_layer(&path, Layer::new(LayerDataTypes::Line(Line::new()), *transform, *style), *insert_index)?;
|
||||
let id = self.add_layer(&path, Layer::new(LayerDataTypes::Line(Line), *transform, *style), *insert_index)?;
|
||||
let path = [path.clone(), vec![id]].concat();
|
||||
|
||||
Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::SelectLayer { path }])
|
||||
|
||||
@@ -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)])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)| {
|
||||
|
||||
Reference in New Issue
Block a user