Resolve most Clippy lint issues

This commit is contained in:
Keavon Chambers 2024-02-29 00:16:12 -08:00
parent 8e769e37f6
commit 70dce1c230
25 changed files with 84 additions and 107 deletions

View file

@ -480,7 +480,7 @@ mod test {
let responses = editor.handle_message(PortfolioMessage::OpenDocumentFile {
document_name: document_name.into(),
document_serialized_content: document_serialized_content.into(),
document_serialized_content,
});
for response in responses {

View file

@ -299,7 +299,7 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
}
WidgetValueUpdate { layout_target, widget_id, value } => {
self.handle_widget_callback(layout_target, widget_id, value, WidgetValueAction::Update, responses);
responses.add(ResendActiveWidget { layout_target, widget_id: widget_id });
responses.add(ResendActiveWidget { layout_target, widget_id });
}
}
}

View file

@ -101,7 +101,7 @@ impl Default for DocumentMessageHandler {
node_graph_handler: Default::default(),
navigation_handler: NavigationMessageHandler::default(),
overlays_message_handler: OverlaysMessageHandler::default(),
properties_panel_message_handler: PropertiesPanelMessageHandler::default(),
properties_panel_message_handler: PropertiesPanelMessageHandler,
// ============================================
// Fields that are saved in the document format
// ============================================
@ -473,12 +473,12 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
.deepest_common_ancestor(self.selected_nodes.selected_layers(self.metadata()), true)
.unwrap_or(LayerNodeIdentifier::ROOT);
let calculated_insert_index = parent.children(&self.metadata()).enumerate().find_map(|(index, direct_child)| {
let calculated_insert_index = parent.children(self.metadata()).enumerate().find_map(|(index, direct_child)| {
if self.selected_nodes.selected_layers(self.metadata()).any(|selected| selected == direct_child) {
return Some(index as isize);
}
for descendant in direct_child.decendants(&self.metadata()) {
for descendant in direct_child.decendants(self.metadata()) {
if self.selected_nodes.selected_layers(self.metadata()).any(|selected| selected == descendant) {
return Some(index as isize);
}
@ -707,7 +707,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
let metadata = self.metadata();
let all_layers_except_artboards = metadata.all_layers().filter(move |&layer| !metadata.is_artboard(layer));
let nodes = all_layers_except_artboards.map(|layer| layer.to_node()).collect();
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: nodes });
responses.add(NodeGraphMessage::SelectedNodesSet { nodes });
}
SelectedLayersLower => {
responses.add(DocumentMessage::SelectedLayersReorder { relative_index_offset: 1 });
@ -886,7 +886,7 @@ impl DocumentMessageHandler {
self.metadata
.root()
.decendants(&self.metadata)
.filter(|&layer| self.selected_nodes.layer_visible(layer, &self.network(), &self.metadata()))
.filter(|&layer| self.selected_nodes.layer_visible(layer, self.network(), self.metadata()))
.filter(|&layer| !is_artboard(layer, network))
.filter_map(|layer| self.metadata.click_target(layer).map(|targets| (layer, targets)))
.filter(move |(layer, target)| target.iter().any(move |target| target.intersect_rectangle(document_quad, self.metadata.transform_to_document(*layer))))
@ -899,7 +899,7 @@ impl DocumentMessageHandler {
self.metadata
.root()
.decendants(&self.metadata)
.filter(|&layer| self.selected_nodes.layer_visible(layer, &self.network(), &self.metadata()))
.filter(|&layer| self.selected_nodes.layer_visible(layer, self.network(), self.metadata()))
.filter_map(|layer| self.metadata.click_target(layer).map(|targets| (layer, targets)))
.filter(move |(layer, target)| target.iter().any(|target: &ClickTarget| target.intersect_point(point, self.metadata.transform_to_document(*layer))))
.map(|(layer, _)| layer)
@ -913,7 +913,7 @@ impl DocumentMessageHandler {
/// Get the combined bounding box of the click targets of the selected visible layers in viewport space
pub fn selected_visible_layers_bounding_box_viewport(&self) -> Option<[DVec2; 2]> {
self.selected_nodes
.selected_visible_layers(&self.network(), &self.metadata())
.selected_visible_layers(self.network(), self.metadata())
.filter_map(|layer| self.metadata.bounding_box_viewport(layer))
.reduce(graphene_core::renderer::Quad::combine_bounds)
}
@ -952,7 +952,7 @@ impl DocumentMessageHandler {
}
/// Returns the bounding boxes for all visible layers.
pub fn bounding_boxes<'a>(&'a self) -> impl Iterator<Item = [DVec2; 2]> + 'a {
pub fn bounding_boxes(&self) -> impl Iterator<Item = [DVec2; 2]> + '_ {
// TODO: Remove this function entirely?
// self.visible_layers().filter_map(|path| self.document_legacy.viewport_bounding_box(path, font_cache).ok()?)
std::iter::empty()
@ -1385,7 +1385,7 @@ impl DocumentMessageHandler {
}
}
(opacity_identical.then(|| first_opacity), blend_mode_identical.then(|| first_blend_mode))
(opacity_identical.then_some(first_opacity), blend_mode_identical.then_some(first_blend_mode))
})
.unwrap_or((None, None));
@ -1406,12 +1406,12 @@ impl DocumentMessageHandler {
let layers_panel_options_bar = WidgetLayout::new(vec![LayoutGroup::Row {
widgets: vec![
DropdownInput::new(blend_mode_menu_entries)
.selected_index(blend_mode.map(|blend_mode| blend_mode.index_in_list_svg_subset()).flatten().map(|index| index as u32))
.selected_index(blend_mode.and_then(|blend_mode| blend_mode.index_in_list_svg_subset()).map(|index| index as u32))
.disabled(disabled)
.draw_icon(false)
.widget_holder(),
Separator::new(SeparatorType::Related).widget_holder(),
NumberInput::new(opacity.map(|opacity| opacity as f64))
NumberInput::new(opacity)
.label("Opacity")
.unit("%")
.display_decimal_places(2)

View file

@ -91,7 +91,7 @@ impl MessageHandler<NavigationMessage, (&DocumentMetadata, Option<[DVec2; 2]>, &
}
responses.add(PortfolioMessage::UpdateDocumentWidgets);
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
FitViewportToSelection => {
if let Some(bounds) = selection_bounds {
@ -188,7 +188,7 @@ impl MessageHandler<NavigationMessage, (&DocumentMetadata, Option<[DVec2; 2]>, &
ptz.tilt = 0.;
ptz.zoom = 1.;
responses.add(PortfolioMessage::UpdateDocumentWidgets);
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
RotateCanvasBegin { was_dispatched_from_menu } => {
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Default });
@ -218,14 +218,14 @@ impl MessageHandler<NavigationMessage, (&DocumentMetadata, Option<[DVec2; 2]>, &
}
SetCanvasTilt { angle_radians } => {
ptz.tilt = angle_radians;
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
responses.add(PortfolioMessage::UpdateDocumentWidgets);
}
SetCanvasZoom { zoom_factor } => {
ptz.zoom = zoom_factor.clamp(VIEWPORT_ZOOM_SCALE_MIN, VIEWPORT_ZOOM_SCALE_MAX);
ptz.zoom *= Self::clamp_zoom(ptz.zoom, document_bounds, old_zoom, ipp);
responses.add(PortfolioMessage::UpdateDocumentWidgets);
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
TransformCanvasEnd { abort_transform } => {
if abort_transform {
@ -236,12 +236,12 @@ impl MessageHandler<NavigationMessage, (&DocumentMetadata, Option<[DVec2; 2]>, &
}
TransformOperation::Pan { pre_commit_pan, .. } => {
ptz.pan = pre_commit_pan;
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
TransformOperation::Zoom { pre_commit_zoom, .. } => {
ptz.zoom = pre_commit_zoom;
responses.add(PortfolioMessage::UpdateDocumentWidgets);
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
}
}
@ -263,7 +263,7 @@ impl MessageHandler<NavigationMessage, (&DocumentMetadata, Option<[DVec2; 2]>, &
ptz.pan += transformed_delta;
responses.add(BroadcastEvent::CanvasTransformed);
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
TranslateCanvasBegin => {
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Grabbing });
@ -279,7 +279,7 @@ impl MessageHandler<NavigationMessage, (&DocumentMetadata, Option<[DVec2; 2]>, &
let transformed_delta = metadata.document_to_viewport.inverse().transform_vector2(delta * ipp.viewport_bounds.size());
ptz.pan += transformed_delta;
self.create_document_transform(ipp.viewport_bounds.center(), &ptz, responses);
self.create_document_transform(ipp.viewport_bounds.center(), ptz, responses);
}
WheelCanvasTranslate { use_y_as_x } => {
let delta = match use_y_as_x {

View file

@ -102,7 +102,7 @@ impl<'a> ModifyInputsContext<'a> {
}
*output = NodeOutput::new(*node_id, *output_index)
}
return None;
None
}
pub fn create_layer(&mut self, new_id: NodeId, output_node_id: NodeId, input_index: usize, skip_layer_nodes: usize) -> Option<NodeId> {
@ -421,7 +421,7 @@ impl<'a> ModifyInputsContext<'a> {
.filter(|transform| transform.matrix2.determinant() != 0. && upstream_transform.matrix2.determinant() != 0.)
.is_some()
{
transform = transform * upstream_transform.inverse();
transform *= upstream_transform.inverse();
}
let final_transform = pivot.inverse() * to.inverse() * transform * pivot;
transform_utils::update_transform(inputs, final_transform);
@ -804,7 +804,7 @@ fn import_usvg_node(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node,
match node {
usvg::Node::Group(group) => {
for child in &group.children {
import_usvg_node(modify_inputs, &child, transform, NodeId(generate_uuid()), LayerNodeIdentifier::new_unchecked(layer), -1);
import_usvg_node(modify_inputs, child, transform, NodeId(generate_uuid()), LayerNodeIdentifier::new_unchecked(layer), -1);
}
modify_inputs.layer_node = Some(layer);
}

View file

@ -304,7 +304,7 @@ impl NodeGraphMessageHandler {
.collect::<Vec<_>>()
}
fn collect_nodes(&self, links: &Vec<FrontendNodeLink>, network: &NodeNetwork) -> Vec<FrontendNode> {
fn collect_nodes(&self, links: &[FrontendNodeLink], network: &NodeNetwork) -> Vec<FrontendNode> {
let connected_node_to_output_lookup = links.iter().map(|link| ((link.link_start, link.link_start_output_index), link.link_end)).collect::<HashMap<_, _>>();
let mut nodes = Vec::new();

View file

@ -1554,16 +1554,12 @@ pub fn transform_properties(document_node: &DocumentNode, node_id: NodeId, _cont
{
widgets.extend_from_slice(&[
Separator::new(SeparatorType::Unrelated).widget_holder(),
NumberInput::new(Some(val.to_degrees().into()))
NumberInput::new(Some(val.to_degrees()))
.unit("°")
.mode(NumberInputMode::Range)
.range_min(Some(-180.))
.range_max(Some(180.))
.on_update(update_value(
|number_input: &NumberInput| TaggedValue::F64((number_input.value.unwrap() as f64).to_radians()),
node_id,
index,
))
.on_update(update_value(|number_input: &NumberInput| TaggedValue::F64(number_input.value.unwrap().to_radians()), node_id, index))
.on_commit(commit_value)
.widget_holder(),
]);

View file

@ -92,7 +92,7 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
let grid = grid.clone();
move |input: &I| {
let mut grid = grid.clone();
update(&mut grid, &input);
update(&mut grid, input);
DocumentMessage::GridOptions(grid).into()
}
}
@ -113,14 +113,14 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
.label("X")
.unit(" px")
.min_width(98)
.on_update(update_origin(&grid, |grid| Some(&mut grid.origin.x)))
.on_update(update_origin(grid, |grid| Some(&mut grid.origin.x)))
.widget_holder(),
Separator::new(SeparatorType::Related).widget_holder(),
NumberInput::new(Some(grid.origin.y))
.label("Y")
.unit(" px")
.min_width(98)
.on_update(update_origin(&grid, |grid| Some(&mut grid.origin.y)))
.on_update(update_origin(grid, |grid| Some(&mut grid.origin.y)))
.widget_holder(),
],
});
@ -148,7 +148,7 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
.unit(" px")
.min(0.)
.min_width(98)
.on_update(update_origin(&grid, |grid| grid.grid_type.rect_spacing().map(|spacing| &mut spacing.x)))
.on_update(update_origin(grid, |grid| grid.grid_type.rect_spacing().map(|spacing| &mut spacing.x)))
.widget_holder(),
Separator::new(SeparatorType::Related).widget_holder(),
NumberInput::new(Some(spacing.y))
@ -156,7 +156,7 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
.unit(" px")
.min(0.)
.min_width(98)
.on_update(update_origin(&grid, |grid| grid.grid_type.rect_spacing().map(|spacing| &mut spacing.y)))
.on_update(update_origin(grid, |grid| grid.grid_type.rect_spacing().map(|spacing| &mut spacing.y)))
.widget_holder(),
],
}),
@ -169,7 +169,7 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
.unit(" px")
.min(0.)
.min_width(200)
.on_update(update_origin(&grid, |grid| grid.grid_type.isometric_y_spacing()))
.on_update(update_origin(grid, |grid| grid.grid_type.isometric_y_spacing()))
.widget_holder(),
],
});
@ -180,13 +180,13 @@ pub fn overlay_options(grid: &GridSnapping) -> Vec<LayoutGroup> {
NumberInput::new(Some(angle_a))
.unit("°")
.min_width(98)
.on_update(update_origin(&grid, |grid| grid.grid_type.angle_a()))
.on_update(update_origin(grid, |grid| grid.grid_type.angle_a()))
.widget_holder(),
Separator::new(SeparatorType::Related).widget_holder(),
NumberInput::new(Some(angle_b))
.unit("°")
.min_width(98)
.on_update(update_origin(&grid, |grid| grid.grid_type.angle_b()))
.on_update(update_origin(grid, |grid| grid.grid_type.angle_b()))
.widget_holder(),
],
});

View file

@ -418,7 +418,7 @@ impl<'a> Selected<'a> {
match &self.original_transforms {
OriginalTransforms::Layer(layer_transforms) => Self::transform_layer(self.document_metadata, layer, layer_transforms.get(&layer), transformation, self.responses),
OriginalTransforms::Path(path_transforms) => Self::transform_path(&self.document_metadata, layer, path_transforms.get(&layer), transformation, self.responses),
OriginalTransforms::Path(path_transforms) => Self::transform_path(self.document_metadata, layer, path_transforms.get(&layer), transformation, self.responses),
}
}
}

View file

@ -109,7 +109,7 @@ impl LayerSnapper {
target: path.target,
distance,
tolerance,
curves: [path.bounds.is_none().then(|| path.document_curve), None],
curves: [path.bounds.is_none().then_some(path.document_curve), None],
source: point.source,
target_bounds: path.bounds,
..Default::default()
@ -148,7 +148,7 @@ impl LayerSnapper {
target: path.target,
distance,
tolerance,
curves: [path.bounds.is_none().then(|| path.document_curve), Some(constraint_path)],
curves: [path.bounds.is_none().then_some(path.document_curve), Some(constraint_path)],
source: point.source,
target_bounds: path.bounds,
at_intersection: true,
@ -187,7 +187,7 @@ impl LayerSnapper {
}
}
for &layer in snap_data.get_candidates() {
get_layer_snap_points(layer, &snap_data, &mut self.points_to_snap);
get_layer_snap_points(layer, snap_data, &mut self.points_to_snap);
if snap_data.ignore_bounds(layer) {
continue;
@ -219,7 +219,7 @@ impl LayerSnapper {
distance < best.distance
}
};
if distance < tolerance && (best.is_none() || best.as_ref().is_some_and(|best| candidate_better(best))) {
if distance < tolerance && (best.is_none() || best.as_ref().is_some_and(candidate_better)) {
best = Some(SnappedPoint {
snapped_point_document: candidate.document_point,
source: point.source,
@ -318,7 +318,7 @@ impl SnapCandidatePoint {
document_point,
source,
target,
quad: quad,
quad,
..Default::default()
}
}
@ -423,8 +423,8 @@ pub fn group_smooth(group: &bezier_rs::ManipulatorGroup<ManipulatorGroupId>, to_
let handle_in = group.in_handle.map(|handle| anchor - handle).filter(handle_not_under(to_document));
let handle_out = group.out_handle.map(|handle| handle - anchor).filter(handle_not_under(to_document));
let at_end = !subpath.closed() && (index == 0 || index == subpath.len() - 1);
let smooth = handle_in.is_some_and(|handle_in| handle_out.is_some_and(|handle_out| handle_in.angle_between(handle_out) < 1e-5)) && !at_end;
smooth
handle_in.is_some_and(|handle_in| handle_out.is_some_and(|handle_out| handle_in.angle_between(handle_out) < 1e-5)) && !at_end
}
pub fn get_layer_snap_points(layer: LayerNodeIdentifier, snap_data: &SnapData, points: &mut Vec<SnapCandidatePoint>) {
let document = snap_data.document;

View file

@ -153,10 +153,10 @@ impl SelectedEdges {
let snapped_bounds = bounds_to_doc.inverse().transform_point2(snapped.snapped_point_document);
let mut scale_factor = (snapped_bounds - pivot) / (updated - pivot);
if !(self.left || self.right) && !constrain {
if !(self.left || self.right || constrain) {
scale_factor.x = 1.
}
if !(self.top || self.bottom) && !constrain {
if !(self.top || self.bottom || constrain) {
scale_factor.y = 1.
}

View file

@ -179,20 +179,14 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, DocumentId, &InputPre
}
ToolMessage::PreUndo => {
let tool_data = &mut self.tool_state.tool_data;
match tool_data.active_tool_type {
ToolType::Pen => {}
_ => {
responses.add(BroadcastEvent::ToolAbort);
}
if tool_data.active_tool_type != ToolType::Pen {
responses.add(BroadcastEvent::ToolAbort);
}
}
ToolMessage::Redo => {
let tool_data = &mut self.tool_state.tool_data;
match tool_data.active_tool_type {
ToolType::Pen => {
responses.add(PenToolMessage::Redo);
}
_ => {}
if tool_data.active_tool_type == ToolType::Pen {
responses.add(PenToolMessage::Redo);
}
}
ToolMessage::RefreshToolOptions => {
@ -241,11 +235,8 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, DocumentId, &InputPre
}
ToolMessage::Undo => {
let tool_data = &mut self.tool_state.tool_data;
match tool_data.active_tool_type {
ToolType::Pen => {
responses.add(PenToolMessage::Undo);
}
_ => {}
if tool_data.active_tool_type == ToolType::Pen {
responses.add(PenToolMessage::Undo);
}
}

View file

@ -259,7 +259,7 @@ impl Fsm for FreehandToolFsmState {
FreehandToolFsmState::Drawing
}
(FreehandToolFsmState::Drawing, FreehandToolMessage::PointerMove) => {
if let Some(layer) = tool_data.layer.clone() {
if let Some(layer) = tool_data.layer {
let transform = document.metadata().transform_to_viewport(layer);
let pos = transform.inverse().transform_point2(input.mouse.position);

View file

@ -195,22 +195,13 @@ impl ToolTransition for PenTool {
}
}
}
#[derive(Default)]
struct ModifierState {
snap_angle: bool,
lock_angle: bool,
break_handle: bool,
}
impl Default for ModifierState {
fn default() -> Self {
ModifierState {
snap_angle: false,
lock_angle: false,
break_handle: false,
}
}
}
#[derive(Clone, Debug, Default)]
struct PenToolData {
weight: f64,

View file

@ -625,9 +625,9 @@ impl Fsm for SelectToolFsmState {
origin: point.document_point,
direction: total_mouse_delta_document.normalize(),
};
tool_data.snap_manager.constrained_snap(&snap_data, &point, constraint, None)
tool_data.snap_manager.constrained_snap(&snap_data, point, constraint, None)
} else {
tool_data.snap_manager.free_snap(&snap_data, &point, None, false)
tool_data.snap_manager.free_snap(&snap_data, point, None, false)
};
if best_snap.other_snap_better(&snapped) {
offset = snapped.snapped_point_document - point.document_point + mouse_delta_document;
@ -1009,7 +1009,7 @@ impl Fsm for SelectToolFsmState {
}
}
fn not_artboard<'a>(document: &'a DocumentMessageHandler) -> impl Fn(&LayerNodeIdentifier) -> bool + 'a {
fn not_artboard(document: &DocumentMessageHandler) -> impl Fn(&LayerNodeIdentifier) -> bool + '_ {
|&layer| !document.metadata.is_artboard(layer)
}

View file

@ -323,7 +323,7 @@ fn update_spline(tool_data: &SplineToolData, show_preview: bool, responses: &mut
let subpath = bezier_rs::Subpath::new_cubic_spline(points);
let Some(layer) = tool_data.layer.clone() else {
let Some(layer) = tool_data.layer else {
return;
};

View file

@ -232,7 +232,7 @@ impl TextToolData {
responses.add(FrontendMessage::DisplayEditableTextbox {
text: editing_text.text.clone(),
line_width: None,
font_size: editing_text.font_size as f64,
font_size: editing_text.font_size,
color: editing_text.color.unwrap_or(Color::BLACK),
url: font_cache.get_preview_url(&editing_text.font).cloned().unwrap_or_default(),
transform: editing_text.transform.to_cols_array(),
@ -323,7 +323,7 @@ impl TextToolData {
fn get_bounds(&self, text: &str, font_cache: &FontCache) -> Option<[DVec2; 2]> {
let editing_text = self.editing_text.as_ref()?;
let buzz_face = font_cache.get(&editing_text.font).map(|data| load_face(data));
let subpaths = graphene_core::text::to_path(text, buzz_face, editing_text.font_size as f64, None);
let subpaths = graphene_core::text::to_path(text, buzz_face, editing_text.font_size, None);
let bounds = subpaths.iter().filter_map(|subpath| subpath.bounding_box());
let combined_bounds = bounds.reduce(|a, b| [a[0].min(b[0]), a[1].max(b[1])]).unwrap_or_default();
Some(combined_bounds)
@ -378,7 +378,7 @@ impl Fsm for TextToolFsmState {
});
if let Some(editing_text) = tool_data.editing_text.as_ref() {
let buzz_face = font_cache.get(&editing_text.font).map(|data| load_face(data));
let far = graphene_core::text::bounding_box(&tool_data.new_text, buzz_face, editing_text.font_size as f64, None);
let far = graphene_core::text::bounding_box(&tool_data.new_text, buzz_face, editing_text.font_size, None);
if far.x != 0. && far.y != 0. {
let quad = Quad::from_box([DVec2::ZERO, far]);
let transformed_quad = document.metadata().transform_to_viewport(tool_data.layer) * quad;
@ -394,7 +394,7 @@ impl Fsm for TextToolFsmState {
continue;
};
let buzz_face = font_cache.get(font).map(|data| load_face(data));
let far = graphene_core::text::bounding_box(text, buzz_face, font_size as f64, None);
let far = graphene_core::text::bounding_box(text, buzz_face, font_size, None);
let quad = Quad::from_box([DVec2::ZERO, far]);
let multiplied = document.metadata().transform_to_viewport(layer) * quad;
overlay_context.quad(multiplied);

View file

@ -176,7 +176,7 @@ impl NodeRuntime {
}
}
async fn execute_network<'a>(&'a mut self, graph: NodeNetwork, render_config: RenderConfig) -> Result<TaggedValue, String> {
async fn execute_network(&mut self, graph: NodeNetwork, render_config: RenderConfig) -> Result<TaggedValue, String> {
if self.wasm_application_io.is_none() {
self.wasm_application_io = Some(WasmApplicationIo::new().await);
}

View file

@ -1,5 +1,4 @@
#[allow(clippy::too_many_arguments)]
#[allow(clippy::non_snake_case)]
#![allow(clippy::too_many_arguments)]
//
// This file is where functions are defined to be called directly from JS.
// It serves as a thin wrapper over the editor backend API that relies
@ -88,7 +87,7 @@ fn call_closure_with_editor_and_handle(mut f: impl FnMut(&mut Editor, &mut JsEdi
log::error!("Failed to borrow editor handles");
continue;
};
let Some(js_editor) = handles.get_mut(&id) else {
let Some(js_editor) = handles.get_mut(id) else {
log::error!("Editor ID ({id}) has no corresponding JsEditorHandle ID");
continue;
};
@ -608,9 +607,9 @@ impl JsEditorHandle {
/// If the insert index is `None`, it is inserted at the end of the folder (equivalent to index infinity).
#[wasm_bindgen(js_name = moveLayerInTree)]
pub fn move_layer_in_tree(&self, insert_parent_id: Option<u64>, insert_index: Option<usize>) {
let insert_parent_id = insert_parent_id.map(|id| NodeId(id));
let insert_parent_id = insert_parent_id.map(NodeId);
let parent = insert_parent_id.map(|id| LayerNodeIdentifier::new_unchecked(id)).unwrap_or(LayerNodeIdentifier::default());
let parent = insert_parent_id.map(LayerNodeIdentifier::new_unchecked).unwrap_or_default();
let message = DocumentMessage::MoveSelectedLayersTo {
parent,
insert_index: insert_index.map(|x| x as isize).unwrap_or(-1),
@ -694,7 +693,7 @@ impl JsEditorHandle {
/// Notifies the backend that the user selected a node in the node graph
#[wasm_bindgen(js_name = selectNodes)]
pub fn select_nodes(&self, nodes: Vec<u64>) {
let nodes = nodes.into_iter().map(|id| NodeId(id)).collect::<Vec<_>>();
let nodes = nodes.into_iter().map(NodeId).collect::<Vec<_>>();
let message = NodeGraphMessage::SelectedNodesSet { nodes };
self.dispatch(message);
}
@ -767,7 +766,7 @@ impl JsEditorHandle {
/// Returns the string representation of the nodes contents
#[wasm_bindgen(js_name = introspectNode)]
pub fn introspect_node(&self, node_path: Vec<u64>) -> JsValue {
let node_path = node_path.into_iter().map(|id| NodeId(id)).collect::<Vec<_>>();
let node_path = node_path.into_iter().map(NodeId).collect::<Vec<_>>();
let frontend_messages = EDITOR_INSTANCES.with(|instances| {
// Mutably borrow the editors, and if successful, we can access them in the closure
instances.try_borrow_mut().map(|mut editors| {
@ -823,7 +822,7 @@ pub fn evaluate_math_expression(expression: &str) -> Option<f64> {
// Insert asterisks where implicit multiplication is used in the expression string
let expression = implicit_multiplication_preprocess(expression);
meval::eval_str_with_context(&expression, &context).ok()
meval::eval_str_with_context(expression, &context).ok()
}
// Modified from this public domain snippet: <https://gist.github.com/Titaniumtown/c181be5d06505e003d8c4d1e372684ff>
@ -877,7 +876,7 @@ pub fn implicit_multiplication_preprocess(expression: &str) -> String {
}
// We have to convert the Greek symbols back to ASCII because meval doesn't support unicode symbols as context constants
output_string.replace("logtwo(", "log2(").replace("π", "pi").replace("τ", "tau")
output_string.replace("logtwo(", "log2(").replace('π', "pi").replace('τ', "tau")
}
#[test]

View file

@ -291,7 +291,7 @@ impl GraphicElement {
}
GraphicElement::ImageFrame(image_frame) => {
if image_frame.image.width * image_frame.image.height == 0 {
return usvg::Node::Group(Box::new(usvg::Group::default()));
return usvg::Node::Group(Box::default());
}
let png = image_frame.image.to_png();
usvg::Node::Image(Box::new(usvg::Image {
@ -338,7 +338,7 @@ impl GraphicElement {
usvg::Node::Group(Box::new(group_element))
}
// TODO
GraphicElement::Artboard(_board) => usvg::Node::Group(Box::new(usvg::Group::default())),
GraphicElement::Artboard(_board) => usvg::Node::Group(Box::default()),
}
}
}

View file

@ -266,7 +266,7 @@ impl GraphicElementRendered for GraphicGroup {
}
fn add_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
for element in self.elements.iter().cloned() {
for element in self.elements.iter() {
let mut new_click_targets = Vec::new();
element.add_click_targets(&mut new_click_targets);
for click_target in new_click_targets.iter_mut() {
@ -501,7 +501,7 @@ impl GraphicElementRendered for ImageFrame<Color> {
fn to_usvg_node(&self) -> usvg::Node {
let image_frame = self;
if image_frame.image.width * image_frame.image.height == 0 {
return usvg::Node::Group(Box::new(usvg::Group::default()));
return usvg::Node::Group(Box::default());
}
let png = image_frame.image.to_png();
usvg::Node::Image(Box::new(usvg::Image {

View file

@ -17,5 +17,5 @@ pub struct TextGeneratorNode<Text, FontName, Size> {
#[node_fn(TextGeneratorNode)]
fn generate_text<'a: 'input, T>(editor: EditorApi<'a, T>, text: String, font_name: Font, font_size: f64) -> crate::vector::VectorData {
let buzz_face = editor.font_cache.get(&font_name).map(|data| load_face(data));
crate::vector::VectorData::from_subpaths(to_path(&text, buzz_face, font_size as f64, None))
crate::vector::VectorData::from_subpaths(to_path(&text, buzz_face, font_size, None))
}

View file

@ -13,7 +13,7 @@ pub struct CircleGenerator<Radius> {
#[node_macro::node_fn(CircleGenerator)]
fn circle_generator(_input: (), radius: f64) -> VectorData {
let radius: f64 = radius.into();
let radius: f64 = radius;
super::VectorData::from_subpath(Subpath::new_ellipse(DVec2::splat(-radius), DVec2::splat(radius)))
}
@ -25,7 +25,7 @@ pub struct EllipseGenerator<RadiusX, RadiusY> {
#[node_macro::node_fn(EllipseGenerator)]
fn ellipse_generator(_input: (), radius_x: f64, radius_y: f64) -> VectorData {
let radius = DVec2::new(radius_x as f64, radius_y as f64);
let radius = DVec2::new(radius_x, radius_y);
let corner1 = -radius;
let corner2 = radius;
super::VectorData::from_subpath(Subpath::new_ellipse(corner1, corner2))
@ -39,7 +39,7 @@ pub struct RectangleGenerator<SizeX, SizeY> {
#[node_macro::node_fn(RectangleGenerator)]
fn square_generator(_input: (), size_x: f64, size_y: f64) -> VectorData {
let size = DVec2::new(size_x as f64, size_y as f64);
let size = DVec2::new(size_x, size_y);
let corner1 = -size / 2.;
let corner2 = size / 2.;
@ -55,7 +55,7 @@ pub struct RegularPolygonGenerator<Points, Radius> {
#[node_macro::node_fn(RegularPolygonGenerator)]
fn regular_polygon_generator(_input: (), points: u32, radius: f64) -> VectorData {
let points = points.into();
let radius: f64 = (radius * 2.).into();
let radius: f64 = radius * 2.;
super::VectorData::from_subpath(Subpath::new_regular_polygon(DVec2::splat(-radius), points, radius))
}
@ -69,8 +69,8 @@ pub struct StarGenerator<Points, Radius, InnerRadius> {
#[node_macro::node_fn(StarGenerator)]
fn star_generator(_input: (), points: u32, radius: f64, inner_radius: f64) -> VectorData {
let points = points.into();
let diameter: f64 = (radius * 2.).into();
let inner_diameter = (inner_radius * 2.).into();
let diameter: f64 = radius * 2.;
let inner_diameter = inner_radius * 2.;
super::VectorData::from_subpath(Subpath::new_star_polygon(DVec2::splat(-diameter), points, diameter, inner_diameter))
}

View file

@ -328,7 +328,7 @@ fn poisson_disk_points(mut vector_data: VectorData, separation_disk_diameter: f6
subpath.apply_transform(vector_data.transform);
let points = subpath.poisson_disk_points(separation_disk_diameter, || rng.gen::<f64>()).into_iter().map(|point| point.into());
let points = subpath.poisson_disk_points(separation_disk_diameter, || rng.gen::<f64>()).into_iter();
*subpath = Subpath::from_anchors(points, false);
subpath.apply_transform(vector_data.transform.inverse());

View file

@ -221,7 +221,7 @@ impl Hash for OriginalLocation {
}
}
impl OriginalLocation {
pub fn inputs<'a>(&'a self, index: usize) -> impl Iterator<Item = Source> + 'a {
pub fn inputs(&self, index: usize) -> impl Iterator<Item = Source> + '_ {
[(index >= self.skip_inputs).then(|| Source {
node: self.path.clone().unwrap_or_default(),
index: self.inputs_exposed.iter().take(index - self.skip_inputs).filter(|&&exposed| exposed).count(),
@ -230,7 +230,7 @@ impl OriginalLocation {
.flatten()
.chain(self.inputs_source.iter().filter(move |x| *x.1 == index).map(|(source, _)| source.clone()))
}
pub fn outputs<'a>(&'a self, index: usize) -> impl Iterator<Item = Source> + 'a {
pub fn outputs(&self, index: usize) -> impl Iterator<Item = Source> + '_ {
[Source {
node: self.path.clone().unwrap_or_default(),
index,