mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00:00
Apply lints and cleanup to Rust code
This commit is contained in:
parent
5388b59e97
commit
d990110f63
27 changed files with 122 additions and 119 deletions
|
|
@ -271,7 +271,7 @@ impl Document {
|
|||
}
|
||||
|
||||
pub fn folder_children_paths(&self, path: &[LayerId]) -> Vec<Vec<LayerId>> {
|
||||
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![]
|
||||
|
|
|
|||
|
|
@ -686,16 +686,7 @@ pub fn line_intersect_point(a: &Line, b: &Line) -> Option<Point> {
|
|||
|
||||
/// Returns intersection point and `t` values, treating lines as Bezier curves.
|
||||
pub fn line_intersection(a: &Line, b: &Line) -> Option<Intersect> {
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -58,11 +58,11 @@ pub enum FrontendMessage {
|
|||
hostname: String,
|
||||
},
|
||||
TriggerImaginateGenerate {
|
||||
parameters: ImaginateGenerationParameters,
|
||||
parameters: Box<ImaginateGenerationParameters>,
|
||||
#[serde(rename = "baseImage")]
|
||||
base_image: Option<ImaginateBaseImage>,
|
||||
base_image: Option<Box<ImaginateBaseImage>>,
|
||||
#[serde(rename = "maskImage")]
|
||||
mask_image: Option<ImaginateMaskImage>,
|
||||
mask_image: Option<Box<ImaginateMaskImage>>,
|
||||
#[serde(rename = "maskPaintMode")]
|
||||
mask_paint_mode: ImaginateMaskPaintMode,
|
||||
#[serde(rename = "maskBlurPx")]
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ impl<'a, const LENGTH: usize> Iterator for BitVectorIter<'a, LENGTH> {
|
|||
type Item = usize;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ impl MessageHandler<NavigationMessage, (&Document, &InputPreprocessorMessageHand
|
|||
}
|
||||
self.snap_zoom = new_snap;
|
||||
|
||||
let difference = self.mouse_position.y as f64 - ipp.mouse.position.y as f64;
|
||||
let difference = self.mouse_position.y - ipp.mouse.position.y;
|
||||
let amount = 1. + difference * VIEWPORT_ZOOM_MOUSE_RATE;
|
||||
|
||||
self.zoom *= amount;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl<'a> MessageHandler<TransformLayerMessage, TransformData<'a>> for TransformL
|
|||
fn process_message(&mut self, message: TransformLayerMessage, (layer_metadata, document, ipp, font_cache): TransformData, responses: &mut VecDeque<Message>) {
|
||||
use TransformLayerMessage::*;
|
||||
|
||||
let selected_layers = layer_metadata.iter().filter_map(|(layer_path, data)| data.selected.then(|| layer_path)).collect::<Vec<_>>();
|
||||
let selected_layers = layer_metadata.iter().filter_map(|(layer_path, data)| data.selected.then_some(layer_path)).collect::<Vec<_>>();
|
||||
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| {
|
||||
|
|
|
|||
|
|
@ -11,19 +11,14 @@ use std::collections::{HashMap, VecDeque};
|
|||
|
||||
pub type OriginalTransforms = HashMap<Vec<LayerId>, 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 {
|
||||
|
|
|
|||
|
|
@ -256,8 +256,8 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
|||
PortfolioMessage::DocumentPassMessage {
|
||||
document_id,
|
||||
message: NodeGraphMessage::SetQualifiedInputValue {
|
||||
layer_path: layer_path.clone(),
|
||||
node_path: node_path.clone(),
|
||||
layer_path,
|
||||
node_path,
|
||||
input_index: get("Status"),
|
||||
value: TaggedValue::ImaginateStatus(status),
|
||||
}
|
||||
|
|
@ -706,11 +706,10 @@ impl PortfolioMessageHandler {
|
|||
// Adjust the output of the graph so we find the relevant output
|
||||
'outer: for end in (0..node_path.len()).rev() {
|
||||
let mut inner_network = &mut network;
|
||||
for index in 0..end {
|
||||
let node_id = node_path[index];
|
||||
inner_network.output = node_id;
|
||||
for node_id in node_path.iter().take(end) {
|
||||
inner_network.output = *node_id;
|
||||
|
||||
let Some(new_inner) = inner_network.nodes.get_mut(&node_id).and_then(|node| node.implementation.get_network_mut()) else {
|
||||
let Some(new_inner) = inner_network.nodes.get_mut(node_id).and_then(|node| node.implementation.get_network_mut()) else {
|
||||
return Err("Failed to find network".to_string());
|
||||
};
|
||||
inner_network = new_inner;
|
||||
|
|
@ -859,9 +858,9 @@ impl PortfolioMessageHandler {
|
|||
|
||||
responses.push_back(
|
||||
FrontendMessage::TriggerImaginateGenerate {
|
||||
parameters,
|
||||
base_image,
|
||||
mask_image,
|
||||
parameters: Box::new(parameters),
|
||||
base_image: base_image.map(Box::new),
|
||||
mask_image: mask_image.map(Box::new),
|
||||
mask_paint_mode: if Self::compute_input::<bool>(&network, &imaginate_node, get("Inpaint"), Cow::Borrowed(&image))? {
|
||||
ImaginateMaskPaintMode::Inpaint
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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] = {
|
||||
|
|
|
|||
|
|
@ -29,18 +29,22 @@ pub struct ShapeEditor {
|
|||
selected_layers: Vec<Vec<LayerId>>,
|
||||
}
|
||||
|
||||
pub struct SelectedPointsInfo<'a> {
|
||||
pub points: Vec<ManipulatorPointInfo<'a>>,
|
||||
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<Message>,
|
||||
) -> 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<Message>) -> Option<SelectedPointsInfo> {
|
||||
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::<Vec<_>>();
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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#"<path d="{}" {}/>"#, self.svg_handle_line_argument().unwrap_or_else(|| "".to_string()), attributes);
|
||||
let _ = write!(svg, r#"<path d="{}" {}/>"#, self.svg_handle_line_argument().unwrap_or_default(), attributes);
|
||||
}
|
||||
|
||||
/// Appends to the `svg` mutable string with an SVG shape representation of the anchors.
|
||||
|
|
|
|||
|
|
@ -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.,
|
||||
|
|
|
|||
|
|
@ -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. {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl<'n, T: 'n + dyn_any::StaticTypeSized> FixedSizeStack<T> {
|
|||
pub fn new(capacity: usize) -> Self {
|
||||
let layout = std::alloc::Layout::array::<MaybeUninit<T>>(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<T>, capacity) as *mut [MaybeUninit<T>]) });
|
||||
let array = Box::into_pin(unsafe { Box::from_raw(core::ptr::slice_from_raw_parts_mut(array as *mut MaybeUninit<T>, capacity)) });
|
||||
|
||||
Self {
|
||||
data: array,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ where
|
|||
type Output = Any<'n>;
|
||||
fn eval(self, input: Any<'n>) -> Self::Output {
|
||||
let node = core::any::type_name::<N>();
|
||||
let input: Box<I> = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str());
|
||||
let input: Box<I> = 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::<N>();
|
||||
let input: Box<I> = dyn_any::downcast(input).expect(format!("DynAnyNode Input in:\n{node}").as_str());
|
||||
let input: Box<I> = dyn_any::downcast(input).unwrap_or_else(|_| panic!("DynAnyNode Input in:\n{node}"));
|
||||
Box::new((&self.0).eval_ref(*input))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ impl<T> CacheNode<T> {
|
|||
CacheNode { cache: OnceCell::new() }
|
||||
}
|
||||
}
|
||||
impl<T> Default for CacheNode<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
impl<T> Cache for CacheNode<T> {
|
||||
fn clear(&mut self) {
|
||||
self.cache = OnceCell::new();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl<'a, I: StaticTypeSized + Sync + Pod + Send, O: StaticTypeSized + Send + Syn
|
|||
fn execute(&self, input: Any<'static>) -> Result<Any<'static>, Box<dyn std::error::Error>> {
|
||||
let input = dyn_any::downcast::<Vec<I>>(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<O> = result.ok_or_else(|| String::from("Failed to execute shader"))?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue