Fix Rust code lints (#1448)

* Fix Rust lints to satisfy Clippy

* Remove some unused commented out code
This commit is contained in:
Keavon Chambers
2023-11-05 13:52:00 -08:00
committed by GitHub
parent f6d104265a
commit 605c0de392
24 changed files with 117 additions and 187 deletions
@@ -22,13 +22,11 @@ use document_legacy::document_metadata::LayerNodeIdentifier;
use document_legacy::layers::blend_mode::BlendMode;
use document_legacy::layers::layer_info::{LayerDataType, LayerDataTypeDiscriminant};
use document_legacy::layers::layer_layer::CachedOutputData;
use document_legacy::layers::style::{RenderData, ViewMode};
use document_legacy::{DocumentError, DocumentResponse, LayerId, Operation as DocumentOperation};
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeInput, NodeNetwork};
use graphene_core::raster::ImageFrame;
use graphene_core::text::Font;
use glam::{DAffine2, DVec2};
use serde::{Deserialize, Serialize};
@@ -891,7 +889,6 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
}
UpdateDocumentTransform { transform } => {
self.document_legacy.metadata.document_to_viewport = transform;
let transform = graphene_core::renderer::format_transform_matrix(transform);
responses.add(DocumentMessage::RenderRulers);
responses.add(DocumentMessage::RenderScrollbars);
responses.add(NodeGraphMessage::RunDocumentGraph);
@@ -993,13 +990,9 @@ impl DocumentMessageHandler {
DocumentRenderMode::OnlyBelowLayerInFolder(below_layer_path) => (self.document_legacy.render_layers_below(below_layer_path, &render_data).unwrap(), None),
DocumentRenderMode::LayerCutout(layer_path, background) => (self.document_legacy.render_layer(layer_path, &render_data).unwrap(), Some(background)),
};
let artboards = match transparent_background {
false => "<!--artboards-->",
true => "".into(),
};
let outside_artboards_color = outside.map_or_else(|| if false { "ffffff" } else { "222222" }.to_string(), |col| col.rgba_hex());
let outside_artboards = match transparent_background {
false => format!(r##"<rect x="0" y="0" width="100%" height="100%" fill="#{outside_artboards_color}" />"##),
let canvas_background_color = outside.map_or_else(|| "222222".to_string(), |col| col.rgba_hex());
let canvas_background = match transparent_background {
false => format!(r##"<rect x="0" y="0" width="100%" height="100%" fill="#{canvas_background_color}" />"##),
true => "".into(),
};
let matrix = transform
@@ -1008,7 +1001,7 @@ impl DocumentMessageHandler {
.enumerate()
.fold(String::new(), |acc, (i, entry)| acc + &(entry.to_string() + if i == 5 { "" } else { "," }));
let svg = format!(
r#"<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" viewBox="0 0 1 1" width="{}" height="{}">{}{outside_artboards}<g transform="matrix({matrix})">{artboards}{artwork}</g></svg>"#,
r#"<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" viewBox="0 0 1 1" width="{}" height="{}">{}{canvas_background}<g transform="matrix({matrix})">{artwork}</g></svg>"#,
size.x, size.y, "\n",
);
@@ -1128,11 +1121,11 @@ impl DocumentMessageHandler {
fn serialize_structure(&self, folder: LayerNodeIdentifier, structure: &mut Vec<u64>, data: &mut Vec<LayerId>, path: &mut Vec<LayerId>) {
let mut space = 0;
for layer_node in folder.children(&self.metadata()) {
for layer_node in folder.children(self.metadata()) {
data.push(layer_node.to_node());
info!("Pushed child");
space += 1;
if layer_node.has_children(&self.metadata()) {
if layer_node.has_children(self.metadata()) {
path.push(layer_node.to_node());
// TODO: Skip if folder is not expanded.
@@ -1197,7 +1190,7 @@ impl DocumentMessageHandler {
// Compute the indices for each layer to be able to sort them
let mut layers_with_indices: Vec<(&[LayerId], Vec<usize>)> = paths
// 'path.len() > 0' filters out root layer since it has no indices
.filter_map(|path| (!path.is_empty()).then_some(path))
.filter(|path| !path.is_empty())
.filter_map(|path| {
// TODO: `indices_for_path` can return an error. We currently skip these layers and log a warning. Once this problem is solved this code can be simplified.
match self.document_legacy.indices_for_path(path) {
@@ -1446,7 +1439,7 @@ impl DocumentMessageHandler {
}
/// Loads layer resources such as creating the blob URLs for the images and loading all of the fonts in the document
pub fn load_layer_resources(&self, responses: &mut VecDeque<Message>, root: &LayerDataType, mut path: Vec<LayerId>, _document_id: u64) {
pub fn load_layer_resources(&self, responses: &mut VecDeque<Message>) {
let mut fonts = HashSet::new();
for (_node_id, node) in self.document_legacy.document_network.recursive_nodes() {
for input in &node.inputs {
@@ -62,7 +62,7 @@ impl<'a> ModifyInputsContext<'a> {
/// Updates the input of an existing node
fn modify_existing_node_inputs(&mut self, node_id: NodeId, update_input: impl FnOnce(&mut Vec<NodeInput>, NodeId, &DocumentMetadata)) {
let document_node = self.network.nodes.get_mut(&node_id).unwrap();
update_input(&mut document_node.inputs, node_id, &self.document_metadata);
update_input(&mut document_node.inputs, node_id, self.document_metadata);
}
pub fn insert_between(&mut self, id: NodeId, pre: NodeOutput, post: NodeOutput, mut node: DocumentNode, input: usize, output: usize, shift_upstream: IVec2) -> Option<NodeId> {
@@ -106,7 +106,7 @@ impl<'a> ModifyInputsContext<'a> {
NodeOutput::new(node_id, 0)
} else {
// The user has connected another node to the output. Insert a layer node between the output and the node.
let mut node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
let node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
let node_id = self.insert_between(generate_uuid(), NodeOutput::new(node_id, output_index), output, node, 0, 0, IVec2::new(-8, 0))?;
NodeOutput::new(node_id, 0)
};
@@ -114,7 +114,7 @@ impl<'a> ModifyInputsContext<'a> {
let node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
self.insert_between(new_id, sibling_layer, output, node, 7, 0, IVec2::new(0, 3))
} else {
let mut layer_node = resolve_document_node_type("Layer").expect("Node").default_document_node();
let layer_node = resolve_document_node_type("Layer").expect("Node").default_document_node();
self.insert_node_before(new_id, output_node_id, input_index, layer_node, IVec2::new(-5, 3))
};
@@ -145,7 +145,6 @@ impl<'a> ModifyInputsContext<'a> {
Default::default(),
);
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
let cull_id = generate_uuid();
self.insert_node_before(generate_uuid(), layer, 0, artboard_node, IVec2::new(-8, 0))
}
@@ -257,7 +256,7 @@ impl<'a> ModifyInputsContext<'a> {
return;
};
let mut new_document_node = node_type.to_document_node_default_inputs([Some(new_input)], metadata);
update_input(&mut new_document_node.inputs, node_id, &self.document_metadata);
update_input(&mut new_document_node.inputs, node_id, self.document_metadata);
self.network.nodes.insert(node_id, new_document_node);
}
@@ -361,7 +360,10 @@ impl<'a> ModifyInputsContext<'a> {
};
let pivot = DAffine2::from_translation(upstream_transform.transform_point2(bounds.layerspace_pivot(transform_utils::get_current_normalized_pivot(inputs))));
if let Some(current_transform) = current_transform.filter(|transform| transform.matrix2.determinant() != 0. && upstream_transform.matrix2.determinant() != 0.) {
if current_transform
.filter(|transform| transform.matrix2.determinant() != 0. && upstream_transform.matrix2.determinant() != 0.)
.is_some()
{
transform = transform * upstream_transform.inverse();
}
let final_transform = pivot.inverse() * to.inverse() * transform * pivot;
@@ -546,7 +548,6 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
modify_inputs.transform_set(transform, transform_in, parent_transform, current_transform, bounds, skip_rerender);
}
let transform = transform.to_cols_array();
}
GraphOperationMessage::TransformSetPivot { layer, pivot } => {
let bounds = LayerBounds::new(document, &layer);
@@ -743,10 +743,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
}
NodeGraphMessage::RunDocumentGraph => responses.add(PortfolioMessage::SubmitGraphRender {
document_id: document_id,
layer_path: Vec::new(),
}),
NodeGraphMessage::RunDocumentGraph => responses.add(PortfolioMessage::SubmitGraphRender { document_id, layer_path: Vec::new() }),
NodeGraphMessage::SendGraph { should_rerender } => {
if let Some(network) = document.document_network.nested_network(&self.network) {
Self::send_graph(network, &self.layer_path, responses);
@@ -1171,7 +1171,7 @@ pub fn logic_operator_properties(document_node: &DocumentNode, node_id: NodeId,
vec![LayoutGroup::Row { widgets }]
}
pub fn transform_properties(document_node: &DocumentNode, node_id: NodeId, context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
pub fn transform_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let translation_assist = |widgets: &mut Vec<WidgetHolder>| {
let pivot_index = 5;
if let NodeInput::Value {
@@ -6,7 +6,6 @@ use crate::messages::tool::common_functionality::shape_editor::ShapeState;
use crate::messages::tool::utility_types::ToolType;
use document_legacy::document::Document;
use document_legacy::document_metadata::LayerNodeIdentifier;
use document_legacy::layers::style::RenderData;
use graphene_core::renderer::Quad;
use graphene_core::vector::{ManipulatorPointId, SelectedType};
@@ -31,13 +30,11 @@ impl OriginalTransforms {
}
}
pub fn update<'a>(&mut self, selected: &'a [LayerNodeIdentifier], responses: &'a mut VecDeque<Message>, document: &'a Document, shape_editor: Option<&'a ShapeState>, tool_type: &'a ToolType) {
pub fn update<'a>(&mut self, selected: &'a [LayerNodeIdentifier], document: &'a Document, shape_editor: Option<&'a ShapeState>) {
match self {
OriginalTransforms::Layer(layer_map) => {
for &layer in selected {
if !layer_map.contains_key(&layer) {
layer_map.insert(layer, document.metadata.transform_to_document(layer));
}
layer_map.entry(layer).or_insert_with(|| document.metadata.transform_to_document(layer));
}
}
OriginalTransforms::Path(path_map) => {
@@ -335,7 +332,7 @@ impl<'a> Selected<'a> {
*original_transforms = OriginalTransforms::Layer(HashMap::new());
}
original_transforms.update(selected, responses, document, shape_editor, tool_type);
original_transforms.update(selected, document, shape_editor);
Self {
selected,
@@ -348,7 +345,7 @@ impl<'a> Selected<'a> {
}
}
pub fn mean_average_of_pivots(&mut self, render_data: &RenderData) -> DVec2 {
pub fn mean_average_of_pivots(&mut self) -> DVec2 {
let xy_summation = self
.selected
.iter()
@@ -359,7 +356,7 @@ impl<'a> Selected<'a> {
xy_summation / self.selected.len() as f64
}
pub fn center_of_aabb(&mut self, render_data: &RenderData) -> DVec2 {
pub fn center_of_aabb(&mut self) -> DVec2 {
let [min, max] = self
.selected
.iter()