mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 22:48:11 +08:00
Resolve most Clippy lint issues
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user