diff --git a/document-legacy/src/document.rs b/document-legacy/src/document.rs index 9b0570c5..0bc4de00 100644 --- a/document-legacy/src/document.rs +++ b/document-legacy/src/document.rs @@ -271,7 +271,7 @@ impl Document { } pub fn folder_children_paths(&self, path: &[LayerId]) -> Vec> { - 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![] diff --git a/document-legacy/src/intersection.rs b/document-legacy/src/intersection.rs index 1d9e486e..3e26c6ee 100644 --- a/document-legacy/src/intersection.rs +++ b/document-legacy/src/intersection.rs @@ -686,16 +686,7 @@ pub fn line_intersect_point(a: &Line, b: &Line) -> Option { /// Returns intersection point and `t` values, treating lines as Bezier curves. pub fn line_intersection(a: &Line, b: &Line) -> Option { - 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. diff --git a/document-legacy/src/layers/folder_layer.rs b/document-legacy/src/layers/folder_layer.rs index bdc7c2e3..f7b9b3b3 100644 --- a/document-legacy/src/layers/folder_layer.rs +++ b/document-legacy/src/layers/folder_layer.rs @@ -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 { diff --git a/document-legacy/src/layers/style/mod.rs b/document-legacy/src/layers/style/mod.rs index e74e6bbf..e6507d14 100644 --- a/document-legacy/src/layers/style/mod.rs +++ b/document-legacy/src/layers/style/mod.rs @@ -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 { diff --git a/editor/src/messages/frontend/frontend_message.rs b/editor/src/messages/frontend/frontend_message.rs index 4e83dd6d..d85f4068 100644 --- a/editor/src/messages/frontend/frontend_message.rs +++ b/editor/src/messages/frontend/frontend_message.rs @@ -58,11 +58,11 @@ pub enum FrontendMessage { hostname: String, }, TriggerImaginateGenerate { - parameters: ImaginateGenerationParameters, + parameters: Box, #[serde(rename = "baseImage")] - base_image: Option, + base_image: Option>, #[serde(rename = "maskImage")] - mask_image: Option, + mask_image: Option>, #[serde(rename = "maskPaintMode")] mask_paint_mode: ImaginateMaskPaintMode, #[serde(rename = "maskBlurPx")] diff --git a/editor/src/messages/input_mapper/utility_types/input_keyboard.rs b/editor/src/messages/input_mapper/utility_types/input_keyboard.rs index 15eaa58f..c16b2359 100644 --- a/editor/src/messages/input_mapper/utility_types/input_keyboard.rs +++ b/editor/src/messages/input_mapper/utility_types/input_keyboard.rs @@ -467,7 +467,7 @@ impl<'a, const LENGTH: usize> Iterator for BitVectorIter<'a, LENGTH> { type Item = usize; fn next(&mut self) -> Option { - while self.iter_index < (STORAGE_SIZE_BITS as usize) * LENGTH { + while self.iter_index < STORAGE_SIZE_BITS * LENGTH { let bit_value = self.bitvector.get(self.iter_index); self.iter_index += 1; diff --git a/editor/src/messages/layout/utility_types/layout_widget.rs b/editor/src/messages/layout/utility_types/layout_widget.rs index 56c84f5f..8e743e8c 100644 --- a/editor/src/messages/layout/utility_types/layout_widget.rs +++ b/editor/src/messages/layout/utility_types/layout_widget.rs @@ -164,7 +164,7 @@ impl Layout { // Simply diff the internal layout (Self::WidgetLayout(current), Self::WidgetLayout(new)) => current.diff(new, widget_path, widget_diffs), (current, Self::WidgetLayout(widget_layout)) => { - // Upate current to the new value + // Update current to the new value *current = Self::WidgetLayout(widget_layout.clone()); // Push an update sublayout value @@ -179,7 +179,7 @@ impl Layout { impl Default for Layout { fn default() -> Self { - Layout::WidgetLayout(WidgetLayout::default()) + Self::WidgetLayout(WidgetLayout::default()) } } diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 8972484e..99740d81 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -1661,7 +1661,10 @@ impl DocumentMessageHandler { direction: SeparatorDirection::Horizontal, })), WidgetHolder::new(Widget::RadioInput(RadioInput { - selected_index: if self.view_mode == ViewMode::Normal { 0 } else { 1 }, + selected_index: match self.view_mode { + ViewMode::Normal => 0, + _ => 1, + }, entries: vec![ RadioEntryData { value: "normal".into(), diff --git a/editor/src/messages/portfolio/document/navigation/navigation_message_handler.rs b/editor/src/messages/portfolio/document/navigation/navigation_message_handler.rs index 2822aff2..b71e59c7 100644 --- a/editor/src/messages/portfolio/document/navigation/navigation_message_handler.rs +++ b/editor/src/messages/portfolio/document/navigation/navigation_message_handler.rs @@ -141,7 +141,7 @@ impl MessageHandler MessageHandler> for TransformL fn process_message(&mut self, message: TransformLayerMessage, (layer_metadata, document, ipp, font_cache): TransformData, responses: &mut VecDeque) { use TransformLayerMessage::*; - let selected_layers = layer_metadata.iter().filter_map(|(layer_path, data)| data.selected.then(|| layer_path)).collect::>(); + let selected_layers = layer_metadata.iter().filter_map(|(layer_path, data)| data.selected.then_some(layer_path)).collect::>(); let mut selected = Selected::new(&mut self.original_transforms, &mut self.pivot, &selected_layers, responses, document); let mut begin_operation = |operation: TransformOperation, typing: &mut Typing, mouse_position: &mut DVec2, start_mouse: &mut DVec2| { diff --git a/editor/src/messages/portfolio/document/utility_types/transformation.rs b/editor/src/messages/portfolio/document/utility_types/transformation.rs index bbf0f808..e0198676 100644 --- a/editor/src/messages/portfolio/document/utility_types/transformation.rs +++ b/editor/src/messages/portfolio/document/utility_types/transformation.rs @@ -11,19 +11,14 @@ use std::collections::{HashMap, VecDeque}; pub type OriginalTransforms = HashMap, DAffine2>; -#[derive(Debug, Clone, PartialEq, Eq, Copy)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Copy)] pub enum Axis { + #[default] Both, X, Y, } -impl Default for Axis { - fn default() -> Self { - Self::Both - } -} - impl Axis { pub fn set_or_toggle(&mut self, target: Axis) { // If constrained to an axis and target is requesting the same axis, toggle back to Both @@ -137,20 +132,15 @@ impl Scale { } } -#[derive(Debug, Clone, PartialEq, Copy)] +#[derive(Default, Debug, Clone, PartialEq, Copy)] pub enum TransformOperation { + #[default] None, Grabbing(Translation), Rotating(Rotation), Scaling(Scale), } -impl Default for TransformOperation { - fn default() -> Self { - TransformOperation::None - } -} - impl TransformOperation { pub fn apply_transform_operation(&self, selected: &mut Selected, snapping: bool) { if self != &TransformOperation::None { diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 1b9e3320..9d581292 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -256,8 +256,8 @@ impl MessageHandler(&network, &imaginate_node, get("Inpaint"), Cow::Borrowed(&image))? { ImaginateMaskPaintMode::Inpaint } else { diff --git a/editor/src/messages/tool/common_functionality/overlay_renderer.rs b/editor/src/messages/tool/common_functionality/overlay_renderer.rs index f6dd6c9d..7f834d7c 100644 --- a/editor/src/messages/tool/common_functionality/overlay_renderer.rs +++ b/editor/src/messages/tool/common_functionality/overlay_renderer.rs @@ -58,7 +58,7 @@ impl OverlayRenderer { // Create, place, and style the manipulator overlays for (manipulator_group_id, manipulator_group) in shape.manipulator_groups().enumerate() { - let manipulator_group_cache = self.manipulator_group_overlay_cache.entry((*layer_id, *manipulator_group_id)).or_insert(Default::default()); + let manipulator_group_cache = self.manipulator_group_overlay_cache.entry((*layer_id, *manipulator_group_id)).or_default(); // Only view in and out handles if they are not on top of the anchor let [in_handle, out_handle] = { diff --git a/editor/src/messages/tool/common_functionality/shape_editor.rs b/editor/src/messages/tool/common_functionality/shape_editor.rs index 35386391..19985f83 100644 --- a/editor/src/messages/tool/common_functionality/shape_editor.rs +++ b/editor/src/messages/tool/common_functionality/shape_editor.rs @@ -29,18 +29,22 @@ pub struct ShapeEditor { selected_layers: Vec>, } +pub struct SelectedPointsInfo<'a> { + pub points: Vec>, + pub offset: DVec2, +} +#[derive(Clone, Copy, Eq, PartialEq)] +pub struct ManipulatorPointInfo<'a> { + pub shape_layer_path: &'a [LayerId], + pub manipulator_group_id: u64, + pub manipulator_type: ManipulatorType, +} + // TODO Consider keeping a list of selected manipulators to minimize traversals of the layers impl ShapeEditor { /// Select the first point within the selection threshold. - /// Returns a tuple of the points if found and the offset, or None otherwise. - pub fn select_point( - &self, - document: &Document, - mouse_position: DVec2, - select_threshold: f64, - add_to_selection: bool, - responses: &mut VecDeque, - ) -> Option<(Vec<(&[LayerId], u64, ManipulatorType)>, DVec2)> { + /// Returns a tuple of the points if found and the offset, or `None` otherwise. + pub fn select_point(&self, document: &Document, mouse_position: DVec2, select_threshold: f64, add_to_selection: bool, responses: &mut VecDeque) -> Option { if self.selected_layers.is_empty() { return None; } @@ -73,7 +77,11 @@ impl ShapeEditor { .enumerate() .filter(|(_id, manipulator_group)| manipulator_group.is_anchor_selected()) .flat_map(|(id, manipulator_group)| manipulator_group.selected_points().map(move |point| (id, point.manipulator_type))) - .map(|(anchor, manipulator_point)| (path.as_slice(), *anchor, manipulator_point)) + .map(|(anchor, manipulator_point)| ManipulatorPointInfo { + shape_layer_path: path.as_slice(), + manipulator_group_id: *anchor, + manipulator_type: manipulator_point, + }) }) .collect::>(); @@ -82,32 +90,36 @@ impl ShapeEditor { // This is selecting the manipulator only for now, next to generalize to points if should_select { + // If we're replacing the selection, clear all points in other selected shapes let add = add_to_selection || is_point_selected; - let point = (manipulator_group_id, ManipulatorType::from_index(manipulator_point_index)); - // Clear all point in other selected shapes if !add { + points.clear(); responses.push_back(DocumentMessage::DeselectAllManipulatorPoints.into()); - points = vec![(shape_layer_path, point.0, point.1)]; - } else { - points.push((shape_layer_path, point.0, point.1)); } + + // Add to the selected points + let point_info = ManipulatorPointInfo { + shape_layer_path, + manipulator_group_id, + manipulator_type: ManipulatorType::from_index(manipulator_point_index), + }; + points.push(point_info); responses.push_back( Operation::SelectManipulatorPoints { layer_path: shape_layer_path.to_vec(), - point_ids: vec![point], + point_ids: vec![(point_info.manipulator_group_id, point_info.manipulator_type)], add, } .into(), ); // Offset to snap the selected point to the cursor - let offset = if let Ok(viewspace) = document.generate_transform_relative_to_viewport(shape_layer_path) { - mouse_position - viewspace.transform_point2(point_position) - } else { - DVec2::ZERO - }; + let offset = document + .generate_transform_relative_to_viewport(shape_layer_path) + .map(|viewspace| mouse_position - viewspace.transform_point2(point_position)) + .unwrap_or_default(); - return Some((points, offset)); + return Some(SelectedPointsInfo { points, offset }); } else { responses.push_back( Operation::DeselectManipulatorPoints { @@ -116,7 +128,13 @@ impl ShapeEditor { } .into(), ); - points.retain(|x| *x != (shape_layer_path, manipulator_group_id, ManipulatorType::from_index(manipulator_point_index))); + points.retain(|x| { + *x != ManipulatorPointInfo { + shape_layer_path, + manipulator_group_id, + manipulator_type: ManipulatorType::from_index(manipulator_point_index), + } + }); return None; } diff --git a/editor/src/messages/tool/common_functionality/snapping.rs b/editor/src/messages/tool/common_functionality/snapping.rs index 9f3ce2ec..6a32a093 100644 --- a/editor/src/messages/tool/common_functionality/snapping.rs +++ b/editor/src/messages/tool/common_functionality/snapping.rs @@ -1,3 +1,4 @@ +use super::shape_editor::ManipulatorPointInfo; use crate::application::generate_uuid; use crate::consts::{ COLOR_ACCENT, SNAP_AXIS_OVERLAY_FADE_DISTANCE, SNAP_AXIS_TOLERANCE, SNAP_AXIS_UNSNAPPED_OPACITY, SNAP_POINT_OVERLAY_FADE_FAR, SNAP_POINT_OVERLAY_FADE_NEAR, SNAP_POINT_SIZE, SNAP_POINT_TOLERANCE, @@ -257,7 +258,7 @@ impl SnapManager { layer: &Layer, path: &[LayerId], include_handles: bool, - ignore_points: &[(&[LayerId], u64, ManipulatorType)], + ignore_points: &[ManipulatorPointInfo], ) { if let LayerDataType::Shape(shape_layer) = &layer.data { let transform = document_message_handler.document_legacy.multiply_transforms(path).unwrap(); @@ -277,7 +278,13 @@ impl SnapManager { } }) .filter_map(|(id, point)| point.as_ref().map(|val| (id, val))) - .filter(|(id, point)| !ignore_points.contains(&(path, *id, point.manipulator_type))) + .filter(|(id, point)| { + !ignore_points.contains(&ManipulatorPointInfo { + shape_layer_path: path, + manipulator_group_id: *id, + manipulator_type: point.manipulator_type, + }) + }) .map(|(_id, point)| DVec2::new(point.position.x, point.position.y)) .map(|pos| transform.transform_point2(pos)); self.add_snap_points(document_message_handler, input, snap_points); @@ -291,7 +298,7 @@ impl SnapManager { input: &InputPreprocessorMessageHandler, include_handles: &[&[LayerId]], exclude: &[&[LayerId]], - ignore_points: &[(&[LayerId], u64, ManipulatorType)], + ignore_points: &[ManipulatorPointInfo], ) { for path in document_message_handler.all_layers() { if !exclude.contains(&path) { diff --git a/editor/src/messages/tool/tool_messages/path_tool.rs b/editor/src/messages/tool/tool_messages/path_tool.rs index f6846c0d..155a69fc 100644 --- a/editor/src/messages/tool/tool_messages/path_tool.rs +++ b/editor/src/messages/tool/tool_messages/path_tool.rs @@ -4,7 +4,7 @@ use crate::messages::input_mapper::utility_types::input_keyboard::{Key, MouseMot use crate::messages::layout::utility_types::layout_widget::PropertyHolder; use crate::messages::prelude::*; use crate::messages::tool::common_functionality::overlay_renderer::OverlayRenderer; -use crate::messages::tool::common_functionality::shape_editor::ShapeEditor; +use crate::messages::tool::common_functionality::shape_editor::{ManipulatorPointInfo, ShapeEditor}; use crate::messages::tool::common_functionality::snapping::SnapManager; use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType}; use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo}; @@ -157,10 +157,9 @@ impl Fsm for PathToolFsmState { let toggle_add_to_selection = input.keyboard.get(add_to_selection as usize); // Select the first point within the threshold (in pixels) - if let Some((mut new_selected, offset)) = - tool_data - .shape_editor - .select_point(&document.document_legacy, input.mouse.position, SELECTION_THRESHOLD, toggle_add_to_selection, responses) + if let Some(mut selected_points) = tool_data + .shape_editor + .select_point(&document.document_legacy, input.mouse.position, SELECTION_THRESHOLD, toggle_add_to_selection, responses) { responses.push_back(DocumentMessage::StartTransaction.into()); @@ -171,18 +170,24 @@ impl Fsm for PathToolFsmState { // Do not snap against handles when anchor is selected let mut extension = Vec::new(); - for &(path, id, point_type) in new_selected.iter() { - if point_type == ManipulatorType::Anchor { - extension.push((path, id, ManipulatorType::InHandle)); - extension.push((path, id, ManipulatorType::OutHandle)); + for point in selected_points.points.iter() { + if point.manipulator_type == ManipulatorType::Anchor { + extension.push(ManipulatorPointInfo { + manipulator_type: ManipulatorType::InHandle, + ..*point + }); + extension.push(ManipulatorPointInfo { + manipulator_type: ManipulatorType::OutHandle, + ..*point + }); } } - new_selected.extend(extension); + selected_points.points.extend(extension); let include_handles = tool_data.shape_editor.selected_layers_ref(); - tool_data.snap_manager.add_all_document_handles(document, input, &include_handles, &[], &new_selected); + tool_data.snap_manager.add_all_document_handles(document, input, &include_handles, &[], &selected_points.points); - tool_data.drag_start_pos = input.mouse.position - offset; + tool_data.drag_start_pos = input.mouse.position - selected_points.offset; PathToolFsmState::Dragging } // We didn't find a point nearby, so consider selecting the nearest shape instead diff --git a/editor/src/messages/tool/utility_types.rs b/editor/src/messages/tool/utility_types.rs index 7bb494e6..350770a1 100644 --- a/editor/src/messages/tool/utility_types.rs +++ b/editor/src/messages/tool/utility_types.rs @@ -287,7 +287,7 @@ pub struct ToolFsmState { impl Default for ToolFsmState { fn default() -> Self { - ToolFsmState { + Self { tool_data: ToolData { active_tool_type: ToolType::Select, tools: list_tools_in_groups() diff --git a/libraries/bezier-rs/src/bezier/core.rs b/libraries/bezier-rs/src/bezier/core.rs index a82f9c8a..3b26ea63 100644 --- a/libraries/bezier-rs/src/bezier/core.rs +++ b/libraries/bezier-rs/src/bezier/core.rs @@ -150,7 +150,7 @@ impl Bezier { /// Appends to the `svg` mutable string with an SVG shape representation of the handle lines. pub fn handle_lines_to_svg(&self, svg: &mut String, attributes: String) { - let _ = write!(svg, r#""#, self.svg_handle_line_argument().unwrap_or_else(|| "".to_string()), attributes); + let _ = write!(svg, r#""#, self.svg_handle_line_argument().unwrap_or_default(), attributes); } /// Appends to the `svg` mutable string with an SVG shape representation of the anchors. diff --git a/libraries/bezier-rs/src/bezier/structs.rs b/libraries/bezier-rs/src/bezier/structs.rs index 60a36b3c..04b9e38f 100644 --- a/libraries/bezier-rs/src/bezier/structs.rs +++ b/libraries/bezier-rs/src/bezier/structs.rs @@ -16,7 +16,7 @@ pub struct ProjectionOptions { impl Default for ProjectionOptions { fn default() -> Self { - ProjectionOptions { + Self { lut_size: 20, convergence_epsilon: 1e-4, convergence_limit: 3, @@ -56,7 +56,7 @@ pub struct ArcsOptions { impl Default for ArcsOptions { fn default() -> Self { - ArcsOptions { + Self { strategy: ArcStrategy::Automatic, error: 0.5, max_iterations: 100, @@ -85,7 +85,7 @@ impl Debug for CircleArc { impl Default for CircleArc { fn default() -> Self { - CircleArc { + Self { center: DVec2::ZERO, radius: 0., start_angle: 0., diff --git a/libraries/bezier-rs/src/bezier/transform.rs b/libraries/bezier-rs/src/bezier/transform.rs index 087b70b5..5cf7d5ea 100644 --- a/libraries/bezier-rs/src/bezier/transform.rs +++ b/libraries/bezier-rs/src/bezier/transform.rs @@ -61,8 +61,8 @@ impl Bezier { }; } // Depending on the order of `t1` and `t2`, determine which half of the split we need to keep - let t1_split_side = if t1 <= t2 { 1 } else { 0 }; - let t2_split_side = if t1 <= t2 { 0 } else { 1 }; + let t1_split_side = usize::from(t1 <= t2); + let t2_split_side = usize::from(t1 > t2); let bezier_starting_at_t1 = self.split(t1)[t1_split_side]; // Adjust the ratio `t2` to its corresponding value on the new curve that was split on `t1` let adjusted_t2 = if t1 < t2 || t1 == 0. { diff --git a/libraries/bezier-rs/src/subpath/manipulators.rs b/libraries/bezier-rs/src/subpath/manipulators.rs index 67e7a541..5d4230f0 100644 --- a/libraries/bezier-rs/src/subpath/manipulators.rs +++ b/libraries/bezier-rs/src/subpath/manipulators.rs @@ -58,7 +58,7 @@ mod tests { let handle2 = DVec2::new(40., 30.); let handle3 = DVec2::new(10., 10.); - return Subpath::new( + Subpath::new( vec![ ManipulatorGroup { anchor: start, @@ -82,7 +82,7 @@ mod tests { }, ], false, - ); + ) } fn set_up_closed_subpath() -> Subpath { diff --git a/libraries/bezier-rs/src/utils.rs b/libraries/bezier-rs/src/utils.rs index 849f54db..9caebd4c 100644 --- a/libraries/bezier-rs/src/utils.rs +++ b/libraries/bezier-rs/src/utils.rs @@ -45,7 +45,7 @@ pub fn get_closest_point_in_lut(lut: &[DVec2], point: DVec2) -> (usize, f64) { lut.iter() .enumerate() .map(|(i, p)| (i, point.distance_squared(*p))) - .min_by(|x, y| (&(x.1)).partial_cmp(&(y.1)).unwrap()) + .min_by(|x, y| (x.1).partial_cmp(&(y.1)).unwrap()) .unwrap() } diff --git a/node-graph/borrow_stack/src/lib.rs b/node-graph/borrow_stack/src/lib.rs index 32c35c91..ee9116ec 100644 --- a/node-graph/borrow_stack/src/lib.rs +++ b/node-graph/borrow_stack/src/lib.rs @@ -26,7 +26,7 @@ impl<'n, T: 'n + dyn_any::StaticTypeSized> FixedSizeStack { pub fn new(capacity: usize) -> Self { let layout = std::alloc::Layout::array::>(capacity).unwrap(); let array = unsafe { std::alloc::alloc(layout) }; - let array = Box::into_pin(unsafe { Box::from_raw(std::slice::from_raw_parts_mut(array as *mut MaybeUninit, capacity) as *mut [MaybeUninit]) }); + let array = Box::into_pin(unsafe { Box::from_raw(core::ptr::slice_from_raw_parts_mut(array as *mut MaybeUninit, capacity)) }); Self { data: array, diff --git a/node-graph/gstd/src/any.rs b/node-graph/gstd/src/any.rs index 83f2ce2b..48d6cbc3 100644 --- a/node-graph/gstd/src/any.rs +++ b/node-graph/gstd/src/any.rs @@ -32,7 +32,7 @@ where type Output = Any<'n>; fn eval(self, input: Any<'n>) -> Self::Output { let node = core::any::type_name::(); - let input: Box = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str()); + let input: Box = dyn_any::downcast(input).unwrap_or_else(|_| panic!("DynAnyNode Input in:\n{node}")); Box::new(self.0.eval(*input)) } } @@ -43,7 +43,7 @@ where type Output = Any<'n>; fn eval(self, input: Any<'n>) -> Self::Output { let node = core::any::type_name::(); - let input: Box = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str()); + let input: Box = dyn_any::downcast(input).unwrap_or_else(|_| panic!("DynAnyNode Input in:\n{node}")); Box::new((&self.0).eval_ref(*input)) } } diff --git a/node-graph/gstd/src/memo.rs b/node-graph/gstd/src/memo.rs index ea6a9601..bd408a3a 100644 --- a/node-graph/gstd/src/memo.rs +++ b/node-graph/gstd/src/memo.rs @@ -26,6 +26,11 @@ impl CacheNode { CacheNode { cache: OnceCell::new() } } } +impl Default for CacheNode { + fn default() -> Self { + Self::new() + } +} impl Cache for CacheNode { fn clear(&mut self) { self.cache = OnceCell::new(); diff --git a/node-graph/gstd/src/raster.rs b/node-graph/gstd/src/raster.rs index 0b93e827..d72aa661 100644 --- a/node-graph/gstd/src/raster.rs +++ b/node-graph/gstd/src/raster.rs @@ -134,7 +134,7 @@ pub fn export_image_node<'n>() -> impl Node<(Image, &'n str), Output = Result<() FnNode::new(|input: (Image, &str)| { let (image, path) = input; let mut new_image = image::ImageBuffer::new(image.width, image.height); - for ((x, y, pixel), color) in new_image.enumerate_pixels_mut().zip((&image).data.iter()) { + for ((x, y, pixel), color) in new_image.enumerate_pixels_mut().zip(image.data.iter()) { let color: Color = *color; assert!(x < image.width); assert!(y < image.height); diff --git a/node-graph/wgpu-executor/src/executor.rs b/node-graph/wgpu-executor/src/executor.rs index 6f9fb3d1..019d8503 100644 --- a/node-graph/wgpu-executor/src/executor.rs +++ b/node-graph/wgpu-executor/src/executor.rs @@ -30,7 +30,7 @@ impl<'a, I: StaticTypeSized + Sync + Pod + Send, O: StaticTypeSized + Send + Syn fn execute(&self, input: Any<'static>) -> Result, Box> { let input = dyn_any::downcast::>(input).expect("Wrong input type"); let context = &self.context; - let future = execute_shader(context.device.clone(), context.queue.clone(), self.shader.to_vec().into(), *input, self.entry_point.clone()); + let future = execute_shader(context.device.clone(), context.queue.clone(), self.shader.to_vec(), *input, self.entry_point.clone()); let result = future_executor::block_on(future); let result: Vec = result.ok_or_else(|| String::from("Failed to execute shader"))?;