mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-04 03:08:12 +08:00
Fix clippy warnings (#3085)
* Run clippy fix * Clippy v2 * Make const item static * Cargo fmt
This commit is contained in:
@@ -569,7 +569,7 @@ mod test_artboard {
|
||||
async fn get_artboards(editor: &mut EditorTestUtils) -> Table<graphene_std::Artboard> {
|
||||
let instrumented = match editor.eval_graph().await {
|
||||
Ok(instrumented) => instrumented,
|
||||
Err(e) => panic!("Failed to evaluate graph: {}", e),
|
||||
Err(e) => panic!("Failed to evaluate graph: {e}"),
|
||||
};
|
||||
instrumented
|
||||
.grab_all_input::<graphene_std::graphic::extend::NewInput<graphene_std::Artboard>>(&editor.runtime)
|
||||
|
||||
@@ -416,7 +416,10 @@ mod test_freehand {
|
||||
fn verify_path_points(vector_and_transform_list: &[(Vector, DAffine2)], expected_captured_points: &[DVec2], tolerance: f64) -> Result<(), String> {
|
||||
assert_eq!(vector_and_transform_list.len(), 1, "There should be one row of Vector geometry");
|
||||
|
||||
let (vector, transform) = vector_and_transform_list.iter().find(|(data, _)| data.point_domain.ids().len() > 0).ok_or("Could not find path data")?;
|
||||
let (vector, transform) = vector_and_transform_list
|
||||
.iter()
|
||||
.find(|(data, _)| !data.point_domain.ids().is_empty())
|
||||
.ok_or("Could not find path data")?;
|
||||
|
||||
let point_count = vector.point_domain.ids().len();
|
||||
let segment_count = vector.segment_domain.ids().len();
|
||||
@@ -424,7 +427,7 @@ mod test_freehand {
|
||||
let actual_positions: Vec<DVec2> = vector.point_domain.positions().iter().map(|&position| transform.transform_point2(position)).collect();
|
||||
|
||||
if segment_count != point_count - 1 {
|
||||
return Err(format!("Expected segments to be one less than points, got {} segments for {} points", segment_count, point_count));
|
||||
return Err(format!("Expected segments to be one less than points, got {segment_count} segments for {point_count} points"));
|
||||
}
|
||||
|
||||
if point_count != expected_captured_points.len() {
|
||||
@@ -434,7 +437,7 @@ mod test_freehand {
|
||||
for (i, (&expected, &actual)) in expected_captured_points.iter().zip(actual_positions.iter()).enumerate() {
|
||||
let distance = (expected - actual).length();
|
||||
if distance >= tolerance {
|
||||
return Err(format!("Point {} position mismatch: expected {:?}, got {:?} (distance: {})", i, expected, actual, distance));
|
||||
return Err(format!("Point {i} position mismatch: expected {expected:?}, got {actual:?} (distance: {distance})"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,7 +511,7 @@ mod test_freehand {
|
||||
let initial_point_count = initial_vector.point_domain.ids().len();
|
||||
let initial_segment_count = initial_vector.segment_domain.ids().len();
|
||||
|
||||
assert!(initial_point_count >= 2, "Expected at least 2 points in initial path, found {}", initial_point_count);
|
||||
assert!(initial_point_count >= 2, "Expected at least 2 points in initial path, found {initial_point_count}");
|
||||
assert_eq!(
|
||||
initial_segment_count,
|
||||
initial_point_count - 1,
|
||||
@@ -569,17 +572,13 @@ mod test_freehand {
|
||||
|
||||
assert!(
|
||||
extended_point_count > initial_point_count,
|
||||
"Expected more points after extension, initial: {}, after extension: {}",
|
||||
initial_point_count,
|
||||
extended_point_count
|
||||
"Expected more points after extension, initial: {initial_point_count}, after extension: {extended_point_count}"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
extended_segment_count,
|
||||
extended_point_count - 1,
|
||||
"Expected segments to be one less than points, points: {}, segments: {}",
|
||||
extended_point_count,
|
||||
extended_segment_count
|
||||
"Expected segments to be one less than points, points: {extended_point_count}, segments: {extended_segment_count}"
|
||||
);
|
||||
|
||||
let layer_count = {
|
||||
@@ -627,8 +626,8 @@ mod test_freehand {
|
||||
|
||||
let existing_layer_id = {
|
||||
let document = editor.active_document();
|
||||
let layer = document.metadata().all_layers().next().unwrap();
|
||||
layer
|
||||
|
||||
document.metadata().all_layers().next().unwrap()
|
||||
};
|
||||
|
||||
editor
|
||||
@@ -685,9 +684,7 @@ mod test_freehand {
|
||||
|
||||
assert!(
|
||||
final_point_count > initial_point_count,
|
||||
"Expected more points after appending to layer, initial: {}, after append: {}",
|
||||
initial_point_count,
|
||||
final_point_count
|
||||
"Expected more points after appending to layer, initial: {initial_point_count}, after append: {final_point_count}"
|
||||
);
|
||||
|
||||
let expected_new_points = second_path_points.len();
|
||||
|
||||
@@ -552,7 +552,7 @@ mod test_gradient {
|
||||
async fn get_fills(editor: &mut EditorTestUtils) -> Vec<(Fill, DAffine2)> {
|
||||
let instrumented = match editor.eval_graph().await {
|
||||
Ok(instrumented) => instrumented,
|
||||
Err(e) => panic!("Failed to evaluate graph: {}", e),
|
||||
Err(e) => panic!("Failed to evaluate graph: {e}"),
|
||||
};
|
||||
|
||||
let document = editor.active_document();
|
||||
@@ -573,7 +573,7 @@ mod test_gradient {
|
||||
let (fill, transform) = fills.first().unwrap();
|
||||
let gradient = fill.as_gradient().expect("Expected gradient fill type");
|
||||
|
||||
(gradient.clone(), transform.clone())
|
||||
(gradient.clone(), *transform)
|
||||
}
|
||||
|
||||
fn assert_stops_at_positions(actual_positions: &[f64], expected_positions: &[f64], tolerance: f64) {
|
||||
@@ -586,7 +586,7 @@ mod test_gradient {
|
||||
);
|
||||
|
||||
for (i, (actual, expected)) in actual_positions.iter().zip(expected_positions.iter()).enumerate() {
|
||||
assert!((actual - expected).abs() < tolerance, "Stop {}: Expected position near {}, got {}", i, expected, actual);
|
||||
assert!((actual - expected).abs() < tolerance, "Stop {i}: Expected position near {expected}, got {actual}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,8 +713,7 @@ mod test_gradient {
|
||||
let positions: Vec<f64> = updated_gradient.stops.iter().map(|(pos, _)| *pos).collect();
|
||||
assert!(
|
||||
positions.iter().any(|pos| (pos - 0.5).abs() < 0.1),
|
||||
"Expected to find a stop near position 0.5, but found: {:?}",
|
||||
positions
|
||||
"Expected to find a stop near position 0.5, but found: {positions:?}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -782,7 +781,7 @@ mod test_gradient {
|
||||
|
||||
// Verify the end point has been updated to the new position
|
||||
let updated_end = transform.transform_point2(updated_gradient.end);
|
||||
assert!(updated_end.abs_diff_eq(DVec2::new(100., 50.), 1e-10), "Expected end point at (100, 50), got {:?}", updated_end);
|
||||
assert!(updated_end.abs_diff_eq(DVec2::new(100., 50.), 1e-10), "Expected end point at (100, 50), got {updated_end:?}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -202,11 +202,11 @@ impl SelectTool {
|
||||
let list = <BooleanOperation as graphene_std::choice_type::ChoiceTypeStatic>::list();
|
||||
list.iter().flat_map(|i| i.iter()).map(move |(operation, info)| {
|
||||
let mut tooltip = info.label.to_string();
|
||||
if let Some(doc) = info.docstring.as_deref() {
|
||||
if let Some(doc) = info.docstring {
|
||||
tooltip.push_str("\n\n");
|
||||
tooltip.push_str(doc);
|
||||
}
|
||||
IconButton::new(info.icon.as_deref().unwrap(), 24)
|
||||
IconButton::new(info.icon.unwrap(), 24)
|
||||
.tooltip(tooltip)
|
||||
.disabled(selected_count == 0)
|
||||
.on_update(move |_| {
|
||||
@@ -852,7 +852,13 @@ impl Fsm for SelectToolFsmState {
|
||||
if let Some(pivot) = pivot {
|
||||
let offset = tool_data
|
||||
.pivot_gizmo_start
|
||||
.map(|offset| tool_data.pivot_gizmo.pivot_disconnected().then_some(tool_data.drag_current - offset).unwrap_or_default())
|
||||
.map(|offset| {
|
||||
if tool_data.pivot_gizmo.pivot_disconnected() {
|
||||
tool_data.drag_current - offset
|
||||
} else {
|
||||
Default::default()
|
||||
}
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let shift = tool_data.pivot_gizmo_shift.unwrap_or_default();
|
||||
overlay_context.pivot(pivot + offset + shift, angle);
|
||||
@@ -895,7 +901,7 @@ impl Fsm for SelectToolFsmState {
|
||||
color
|
||||
} else {
|
||||
let color_string = &graphene_std::Color::from_rgb_str(color.strip_prefix('#').unwrap()).unwrap().with_alpha(0.25).to_rgba_hex_srgb();
|
||||
&format!("#{}", color_string)
|
||||
&format!("#{color_string}")
|
||||
};
|
||||
let line_center = tool_data.line_center;
|
||||
overlay_context.line(line_center - direction * viewport_diagonal, line_center + direction * viewport_diagonal, Some(color), None);
|
||||
@@ -1455,7 +1461,11 @@ impl Fsm for SelectToolFsmState {
|
||||
tool_data.select_single_layer = None;
|
||||
|
||||
if let Some(start) = tool_data.pivot_gizmo_start {
|
||||
let offset = tool_data.pivot_gizmo.pivot_disconnected().then_some(tool_data.drag_current - start).unwrap_or_default();
|
||||
let offset = if tool_data.pivot_gizmo.pivot_disconnected() {
|
||||
tool_data.drag_current - start
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
if let Some(v) = tool_data.pivot_gizmo.pivot.pivot.as_mut() {
|
||||
*v += offset;
|
||||
}
|
||||
@@ -1649,7 +1659,9 @@ impl Fsm for SelectToolFsmState {
|
||||
}
|
||||
(_, SelectToolMessage::PivotShift { offset, flush }) => {
|
||||
if flush {
|
||||
tool_data.pivot_gizmo.pivot.pivot.as_mut().map(|v| *v += tool_data.pivot_gizmo_shift.take().unwrap_or_default());
|
||||
if let Some(v) = tool_data.pivot_gizmo.pivot.pivot.as_mut() {
|
||||
*v += tool_data.pivot_gizmo_shift.take().unwrap_or_default();
|
||||
}
|
||||
let pivot_gizmo = tool_data.pivot_gizmo();
|
||||
responses.add(TransformLayerMessage::SetPivotGizmo { pivot_gizmo });
|
||||
return self;
|
||||
|
||||
@@ -606,11 +606,7 @@ mod test_spline_tool {
|
||||
|
||||
assert!(
|
||||
distance < epsilon,
|
||||
"Point {} position mismatch: expected {:?}, got {:?} (distance: {})",
|
||||
i,
|
||||
expected_point,
|
||||
actual_point,
|
||||
distance
|
||||
"Point {i} position mismatch: expected {expected_point:?}, got {actual_point:?} (distance: {distance})"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -644,8 +640,8 @@ mod test_spline_tool {
|
||||
// Verify initial spline has correct number of points and segments
|
||||
let initial_point_count = first_vector.point_domain.ids().len();
|
||||
let initial_segment_count = first_vector.segment_domain.ids().len();
|
||||
assert_eq!(initial_point_count, 3, "Expected 3 points in initial spline, found {}", initial_point_count);
|
||||
assert_eq!(initial_segment_count, 2, "Expected 2 segments in initial spline, found {}", initial_segment_count);
|
||||
assert_eq!(initial_point_count, 3, "Expected 3 points in initial spline, found {initial_point_count}");
|
||||
assert_eq!(initial_segment_count, 2, "Expected 2 segments in initial spline, found {initial_segment_count}");
|
||||
|
||||
let layer_to_viewport = document.metadata().transform_to_viewport(spline_layer);
|
||||
|
||||
@@ -679,8 +675,8 @@ mod test_spline_tool {
|
||||
let extended_point_count = extended_vector.point_domain.ids().len();
|
||||
let extended_segment_count = extended_vector.segment_domain.ids().len();
|
||||
|
||||
assert_eq!(extended_point_count, 5, "Expected 5 points in extended spline, found {}", extended_point_count);
|
||||
assert_eq!(extended_segment_count, 4, "Expected 4 segments in extended spline, found {}", extended_segment_count);
|
||||
assert_eq!(extended_point_count, 5, "Expected 5 points in extended spline, found {extended_point_count}");
|
||||
assert_eq!(extended_segment_count, 4, "Expected 4 segments in extended spline, found {extended_segment_count}");
|
||||
|
||||
// Verify the spline node is still the same
|
||||
let extended_spline_node = find_spline(document, spline_layer).expect("Spline node not found after extension");
|
||||
@@ -715,7 +711,7 @@ mod test_spline_tool {
|
||||
|
||||
// Evaluate the graph to ensure everything is processed
|
||||
if let Err(e) = editor.eval_graph().await {
|
||||
panic!("Graph evaluation failed: {}", e);
|
||||
panic!("Graph evaluation failed: {e}");
|
||||
}
|
||||
|
||||
// Get the layer and vector data
|
||||
@@ -755,7 +751,7 @@ mod test_spline_tool {
|
||||
|
||||
// Evaluating the graph to ensure everything is processed
|
||||
if let Err(e) = editor.eval_graph().await {
|
||||
panic!("Graph evaluation failed: {}", e);
|
||||
panic!("Graph evaluation failed: {e}");
|
||||
}
|
||||
|
||||
// Get the layer and vector data
|
||||
@@ -793,7 +789,7 @@ mod test_spline_tool {
|
||||
|
||||
// Evaluating the graph to ensure everything is processed
|
||||
if let Err(e) = editor.eval_graph().await {
|
||||
panic!("Graph evaluation failed: {}", e);
|
||||
panic!("Graph evaluation failed: {e}");
|
||||
}
|
||||
|
||||
// Get the layer and vector data
|
||||
@@ -832,7 +828,7 @@ mod test_spline_tool {
|
||||
|
||||
editor.handle_message(SplineToolMessage::Confirm).await;
|
||||
if let Err(e) = editor.eval_graph().await {
|
||||
panic!("Graph evaluation failed: {}", e);
|
||||
panic!("Graph evaluation failed: {e}");
|
||||
}
|
||||
|
||||
// Get the layer and vector data
|
||||
@@ -889,8 +885,8 @@ mod test_spline_tool {
|
||||
let point_count = vector.point_domain.ids().len();
|
||||
let segment_count = vector.segment_domain.ids().len();
|
||||
|
||||
assert_eq!(point_count, 3, "Expected 3 points in the spline, found {}", point_count);
|
||||
assert_eq!(segment_count, 2, "Expected 2 segments in the spline, found {}", segment_count);
|
||||
assert_eq!(point_count, 3, "Expected 3 points in the spline, found {point_count}");
|
||||
assert_eq!(segment_count, 2, "Expected 2 segments in the spline, found {segment_count}");
|
||||
|
||||
let layer_to_viewport = document.metadata().transform_to_viewport(spline_layer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user