Apply lints and cleanup to Rust code

This commit is contained in:
Keavon Chambers
2023-01-29 03:01:57 -08:00
parent 0d8be71426
commit 6eafeaaecc
27 changed files with 122 additions and 119 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ impl Document {
}
pub fn folder_children_paths(&self, path: &[LayerId]) -> Vec<Vec<LayerId>> {
if let Ok(folder) = self.folder(&path) {
if let Ok(folder) = self.folder(path) {
folder.list_layers().iter().map(|f| [path, &[*f]].concat()).collect()
} else {
vec![]
+1 -10
View File
@@ -686,16 +686,7 @@ pub fn line_intersect_point(a: &Line, b: &Line) -> Option<Point> {
/// Returns intersection point and `t` values, treating lines as Bezier curves.
pub fn line_intersection(a: &Line, b: &Line) -> Option<Intersect> {
match line_intersection_unchecked(a, b) {
Some(intersect) => {
if valid_t(intersect.t_a) && valid_t(intersect.t_b) {
Some(intersect)
} else {
None
}
}
None => None,
}
line_intersection_unchecked(a, b).filter(|intersect| valid_t(intersect.t_a) && valid_t(intersect.t_b))
}
/// Returns intersection point and `t` values, treating lines as rays.
+1 -1
View File
@@ -72,7 +72,7 @@ impl FolderLayer {
let mut insert_index = insert_index as i128;
if insert_index < 0 {
insert_index = self.layers.len() as i128 + insert_index as i128 + 1;
insert_index = self.layers.len() as i128 + insert_index + 1;
}
if insert_index <= self.layers.len() as i128 && insert_index >= 0 {
+6 -21
View File
@@ -21,9 +21,10 @@ fn format_opacity(name: &str, opacity: f32) -> String {
}
/// Represents different ways of rendering an object
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, specta::Type)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, specta::Type)]
pub enum ViewMode {
/// Render with normal coloration at the current viewport resolution
#[default]
Normal,
/// Render only the outlines of shapes at the current viewport resolution
Outline,
@@ -31,12 +32,6 @@ pub enum ViewMode {
Pixels,
}
impl Default for ViewMode {
fn default() -> Self {
ViewMode::Normal
}
}
/// Contains metadata for rendering the document as an svg
#[derive(Debug, Clone, Copy)]
pub struct RenderData<'a> {
@@ -55,18 +50,13 @@ impl<'a> RenderData<'a> {
}
}
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash, Serialize, Deserialize, specta::Type)]
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, Hash, Serialize, Deserialize, specta::Type)]
pub enum GradientType {
#[default]
Linear,
Radial,
}
impl Default for GradientType {
fn default() -> Self {
GradientType::Linear
}
}
/// A gradient fill.
///
/// Contains the start and end points, along with the colors at varying points along the length.
@@ -183,19 +173,14 @@ impl Gradient {
///
/// Can be None, a solid [Color], a linear [Gradient], a radial [Gradient] or potentially some sort of image or pattern in the future
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, specta::Type)]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, specta::Type)]
pub enum Fill {
#[default]
None,
Solid(Color),
Gradient(Gradient),
}
impl Default for Fill {
fn default() -> Self {
Self::None
}
}
impl Fill {
/// Construct a new solid [Fill] from a [Color].
pub fn solid(color: Color) -> Self {