diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface.rs b/editor/src/messages/portfolio/document/utility_types/network_interface.rs index ed485a1f06..a44c790207 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface.rs @@ -1844,12 +1844,12 @@ impl NodeNetworkInterface { if *import_index == 0 { let remove_import_center = reorder_import_center + DVec2::new(-4., 0.); - let remove_import = ClickTarget::new_with_subpath(Subpath::new_rect(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.); + let remove_import = ClickTarget::new_with_subpath(Subpath::new_rectangle(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.); remove_imports_exports.insert_custom_output_port(*import_index, remove_import); } else { let remove_import_center = reorder_import_center + DVec2::new(-12., 0.); - let reorder_import = ClickTarget::new_with_subpath(Subpath::new_rect(reorder_import_center - DVec2::new(3., 4.), reorder_import_center + DVec2::new(3., 4.)), 0.); - let remove_import = ClickTarget::new_with_subpath(Subpath::new_rect(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.); + let reorder_import = ClickTarget::new_with_subpath(Subpath::new_rectangle(reorder_import_center - DVec2::new(3., 4.), reorder_import_center + DVec2::new(3., 4.)), 0.); + let remove_import = ClickTarget::new_with_subpath(Subpath::new_rectangle(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.); reorder_imports_exports.insert_custom_output_port(*import_index, reorder_import); remove_imports_exports.insert_custom_output_port(*import_index, remove_import); } @@ -1864,12 +1864,12 @@ impl NodeNetworkInterface { if *export_index == 0 { let remove_export_center = reorder_export_center + DVec2::new(4., 0.); - let remove_export = ClickTarget::new_with_subpath(Subpath::new_rect(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.); + let remove_export = ClickTarget::new_with_subpath(Subpath::new_rectangle(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.); remove_imports_exports.insert_custom_input_port(*export_index, remove_export); } else { let remove_export_center = reorder_export_center + DVec2::new(12., 0.); - let reorder_export = ClickTarget::new_with_subpath(Subpath::new_rect(reorder_export_center - DVec2::new(3., 4.), reorder_export_center + DVec2::new(3., 4.)), 0.); - let remove_export = ClickTarget::new_with_subpath(Subpath::new_rect(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.); + let reorder_export = ClickTarget::new_with_subpath(Subpath::new_rectangle(reorder_export_center - DVec2::new(3., 4.), reorder_export_center + DVec2::new(3., 4.)), 0.); + let remove_export = ClickTarget::new_with_subpath(Subpath::new_rectangle(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.); reorder_imports_exports.insert_custom_input_port(*export_index, reorder_export); remove_imports_exports.insert_custom_input_port(*export_index, remove_export); } @@ -2482,7 +2482,7 @@ impl NodeNetworkInterface { let node_click_target_bottom_right = node_click_target_top_left + DVec2::new(width as f64, height as f64); let radius = 3.; - let subpath = Subpath::new_rounded_rect(node_click_target_top_left, node_click_target_bottom_right, [radius; 4]); + let subpath = Subpath::new_rounded_rectangle(node_click_target_top_left, node_click_target_bottom_right, [radius; 4]); let node_click_target = ClickTarget::new_with_subpath(subpath, 0.); DocumentNodeClickTargets { @@ -2507,12 +2507,12 @@ impl NodeNetworkInterface { // Update visibility button click target let visibility_offset = node_top_left + DVec2::new(width as f64, 24.); - let subpath = Subpath::new_rounded_rect(DVec2::new(-12., -12.) + visibility_offset, DVec2::new(12., 12.) + visibility_offset, [3.; 4]); + let subpath = Subpath::new_rounded_rectangle(DVec2::new(-12., -12.) + visibility_offset, DVec2::new(12., 12.) + visibility_offset, [3.; 4]); let visibility_click_target = ClickTarget::new_with_subpath(subpath, 0.); // Update grip button click target, which is positioned to the left of the left most icon let grip_offset_right_edge = node_top_left + DVec2::new(width as f64 - (GRID_SIZE as f64) / 2., 24.); - let subpath = Subpath::new_rounded_rect(DVec2::new(-8., -12.) + grip_offset_right_edge, DVec2::new(0., 12.) + grip_offset_right_edge, [0.; 4]); + let subpath = Subpath::new_rounded_rectangle(DVec2::new(-8., -12.) + grip_offset_right_edge, DVec2::new(0., 12.) + grip_offset_right_edge, [0.; 4]); let grip_click_target = ClickTarget::new_with_subpath(subpath, 0.); // Create layer click target, which is contains the layer and the chain background @@ -2521,7 +2521,7 @@ impl NodeNetworkInterface { let node_bottom_right = node_top_left + DVec2::new(width as f64, height as f64); let chain_top_left = node_top_left - DVec2::new((chain_width_grid_spaces * crate::consts::GRID_SIZE) as f64, 0.); let radius = 10.; - let subpath = Subpath::new_rounded_rect(chain_top_left, node_bottom_right, [radius; 4]); + let subpath = Subpath::new_rounded_rectangle(chain_top_left, node_bottom_right, [radius; 4]); let node_click_target = ClickTarget::new_with_subpath(subpath, 0.); DocumentNodeClickTargets { @@ -2747,7 +2747,7 @@ impl NodeNetworkInterface { }); let bounds = self.all_nodes_bounding_box(network_path).cloned().unwrap_or([DVec2::ZERO, DVec2::ZERO]); - let rect = Subpath::::new_rect(bounds[0], bounds[1]); + let rect = Subpath::::new_rectangle(bounds[0], bounds[1]); let all_nodes_bounding_box = rect.to_bezpath().to_svg(); let mut modify_import_export = Vec::new(); @@ -3008,7 +3008,7 @@ impl NodeNetworkInterface { return None; }; - let bounding_box_subpath = Subpath::::new_rect(bounds[0], bounds[1]); + let bounding_box_subpath = Subpath::::new_rectangle(bounds[0], bounds[1]); bounding_box_subpath.bounding_box_with_transform(network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport) } diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index 3ffe8a943e..301e6dc209 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -1081,7 +1081,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId], log::error!("The old Spline node's input at index 1 is not a TaggedValue::VecDVec2"); return None; }; - let vector = Vector::from_subpath(Subpath::from_anchors_linear(points.to_vec(), false)); + let vector = Vector::from_subpath(Subpath::from_anchors(points.to_vec(), false)); // Retrieve the output connectors linked to the "Spline" node's output connector let Some(spline_outputs) = document.network_interface.outward_wires(network_path)?.get(&OutputConnector::node(*node_id, 0)).cloned() else { diff --git a/editor/src/messages/tool/common_functionality/shape_editor.rs b/editor/src/messages/tool/common_functionality/shape_editor.rs index 6723db92e9..a7ab903dfe 100644 --- a/editor/src/messages/tool/common_functionality/shape_editor.rs +++ b/editor/src/messages/tool/common_functionality/shape_editor.rs @@ -2155,7 +2155,7 @@ impl ShapeState { if polygon.len() < 2 { return (points_inside, segments_inside); } - let polygon: Subpath = Subpath::from_anchors_linear(polygon.to_vec(), true); + let polygon: Subpath = Subpath::from_anchors(polygon.to_vec(), true); Some(polygon) } else { None diff --git a/editor/src/messages/tool/tool_messages/select_tool.rs b/editor/src/messages/tool/tool_messages/select_tool.rs index 717903ab10..608da0bc89 100644 --- a/editor/src/messages/tool/tool_messages/select_tool.rs +++ b/editor/src/messages/tool/tool_messages/select_tool.rs @@ -452,7 +452,7 @@ impl SelectToolData { if self.lasso_polygon.len() < 2 { return Vec::new(); } - let polygon = Subpath::from_anchors_linear(self.lasso_polygon.clone(), true); + let polygon = Subpath::from_anchors(self.lasso_polygon.clone(), true); document.intersect_polygon_no_artboards(polygon, viewport).collect() } @@ -460,7 +460,7 @@ impl SelectToolData { if self.lasso_polygon.len() < 2 { return false; } - let polygon = Subpath::from_anchors_linear(self.lasso_polygon.clone(), true); + let polygon = Subpath::from_anchors(self.lasso_polygon.clone(), true); document.is_layer_fully_inside_polygon(layer, viewport, polygon) } diff --git a/node-graph/libraries/rendering/src/renderer.rs b/node-graph/libraries/rendering/src/renderer.rs index 3c765a91ad..fcea51c45c 100644 --- a/node-graph/libraries/rendering/src/renderer.rs +++ b/node-graph/libraries/rendering/src/renderer.rs @@ -470,7 +470,7 @@ impl Render for Artboard { fn collect_metadata(&self, metadata: &mut RenderMetadata, mut footprint: Footprint, element_id: Option) { if let Some(element_id) = element_id { - let subpath = Subpath::new_rect(DVec2::ZERO, self.dimensions.as_dvec2()); + let subpath = Subpath::new_rectangle(DVec2::ZERO, self.dimensions.as_dvec2()); metadata.click_targets.insert(element_id, vec![ClickTarget::new_with_subpath(subpath, 0.)]); metadata.upstream_footprints.insert(element_id, footprint); metadata.local_transforms.insert(element_id, DAffine2::from_translation(self.location.as_dvec2())); @@ -483,7 +483,7 @@ impl Render for Artboard { } fn add_upstream_click_targets(&self, click_targets: &mut Vec) { - let subpath_rectangle = Subpath::new_rect(DVec2::ZERO, self.dimensions.as_dvec2()); + let subpath_rectangle = Subpath::new_rectangle(DVec2::ZERO, self.dimensions.as_dvec2()); click_targets.push(ClickTarget::new_with_subpath(subpath_rectangle, 0.)); } @@ -1363,7 +1363,7 @@ impl Render for Table> { fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option) { let Some(element_id) = element_id else { return }; - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::ONE); metadata.click_targets.insert(element_id, vec![ClickTarget::new_with_subpath(subpath, 0.)]); metadata.upstream_footprints.insert(element_id, footprint); @@ -1374,7 +1374,7 @@ impl Render for Table> { } fn add_upstream_click_targets(&self, click_targets: &mut Vec) { - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::ONE); click_targets.push(ClickTarget::new_with_subpath(subpath, 0.)); } } @@ -1423,7 +1423,7 @@ impl Render for Table> { fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option) { let Some(element_id) = element_id else { return }; - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::ONE); metadata.click_targets.insert(element_id, vec![ClickTarget::new_with_subpath(subpath, 0.)]); metadata.upstream_footprints.insert(element_id, footprint); @@ -1434,7 +1434,7 @@ impl Render for Table> { } fn add_upstream_click_targets(&self, click_targets: &mut Vec) { - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::ONE); click_targets.push(ClickTarget::new_with_subpath(subpath, 0.)); } } diff --git a/node-graph/libraries/vector-types/src/subpath/core.rs b/node-graph/libraries/vector-types/src/subpath/core.rs index c5600d61a1..2d6ff253fd 100644 --- a/node-graph/libraries/vector-types/src/subpath/core.rs +++ b/node-graph/libraries/vector-types/src/subpath/core.rs @@ -156,24 +156,19 @@ impl Subpath { .all(|manipulator_group| manipulator_group.anchor.abs_diff_eq(point, MAX_ABSOLUTE_DIFFERENCE)) } - /// Construct a [Subpath] from an iter of anchor positions. pub fn from_anchors(anchor_positions: impl IntoIterator, closed: bool) -> Self { Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor(anchor)).collect(), closed) } - pub fn from_anchors_linear(anchor_positions: impl IntoIterator, closed: bool) -> Self { - Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor_linear(anchor)).collect(), closed) - } - /// Constructs a rectangle with `corner1` and `corner2` as the two corners. - pub fn new_rect(corner1: DVec2, corner2: DVec2) -> Self { - Self::from_anchors_linear([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true) + pub fn new_rectangle(corner1: DVec2, corner2: DVec2) -> Self { + Self::from_anchors([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true) } /// Constructs a rounded rectangle with `corner1` and `corner2` as the two corners and `corner_radii` as the radii of the corners: `[top_left, top_right, bottom_right, bottom_left]`. - pub fn new_rounded_rect(corner1: DVec2, corner2: DVec2, corner_radii: [f64; 4]) -> Self { + pub fn new_rounded_rectangle(corner1: DVec2, corner2: DVec2, corner_radii: [f64; 4]) -> Self { if corner_radii.iter().all(|radii| radii.abs() < f64::EPSILON * 100.) { - return Self::new_rect(corner1, corner2); + return Self::new_rectangle(corner1, corner2); } use std::f64::consts::{FRAC_1_SQRT_2, PI}; @@ -185,7 +180,7 @@ impl Subpath { return vec![ManipulatorGroup::new_anchor(point1), ManipulatorGroup::new_anchor(point2)]; } - // Based on https://pomax.github.io/bezierinfo/#circles_cubic + // Constant from https://pomax.github.io/bezierinfo/#circles_cubic const HANDLE_OFFSET_FACTOR: f64 = 0.551784777779014; let handle_offset = radius * HANDLE_OFFSET_FACTOR; vec![ diff --git a/node-graph/libraries/vector-types/src/subpath/lookup.rs b/node-graph/libraries/vector-types/src/subpath/lookup.rs index 1c66ceaafb..7b48c23c63 100644 --- a/node-graph/libraries/vector-types/src/subpath/lookup.rs +++ b/node-graph/libraries/vector-types/src/subpath/lookup.rs @@ -120,7 +120,7 @@ mod test_centroid { use super::*; #[test] fn centroid_rect() { - let rect = Subpath::::new_rect(DVec2::new(100., 100.), DVec2::new(300., 200.)); + let rect = Subpath::::new_rectangle(DVec2::new(100., 100.), DVec2::new(300., 200.)); let (centre, area) = rect.area_centroid_and_area(Some(1e-3), Some(1e-3)).unwrap(); assert_eq!(area, 200. * 100.); assert_eq!(centre, DVec2::new(200., 150.)) diff --git a/node-graph/libraries/vector-types/src/subpath/structs.rs b/node-graph/libraries/vector-types/src/subpath/structs.rs index d5f868be2b..1498402292 100644 --- a/node-graph/libraries/vector-types/src/subpath/structs.rs +++ b/node-graph/libraries/vector-types/src/subpath/structs.rs @@ -55,10 +55,6 @@ impl ManipulatorGroup { /// Construct a new manipulator point with just an anchor position pub fn new_anchor(anchor: DVec2) -> Self { - Self::new(anchor, Some(anchor), Some(anchor)) - } - - pub fn new_anchor_linear(anchor: DVec2) -> Self { Self::new(anchor, None, None) } diff --git a/node-graph/libraries/vector-types/src/vector/click_target.rs b/node-graph/libraries/vector-types/src/vector/click_target.rs index de2b79aeaf..9bc1a7c50f 100644 --- a/node-graph/libraries/vector-types/src/vector/click_target.rs +++ b/node-graph/libraries/vector-types/src/vector/click_target.rs @@ -330,7 +330,7 @@ mod tests { let mut cache = BoundingBoxCache::default(); // Create a simple rectangle subpath for testing - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::new(100.0, 50.0)); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100.0, 50.0)); let rotation = PI / 4.0; let scale = DVec2::new(2.0, 2.0); @@ -353,7 +353,7 @@ mod tests { #[test] fn test_bounding_box_cache_ring_buffer_behavior() { let mut cache = BoundingBoxCache::default(); - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::new(10.0, 10.0)); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(10.0, 10.0)); let scale = DVec2::ONE; let translation = DVec2::ZERO; @@ -378,7 +378,7 @@ mod tests { #[test] fn test_click_target_bounding_box_caching() { // Create a click target with a simple rectangle - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::new(100.0, 50.0)); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100.0, 50.0)); let click_target = ClickTarget::new_with_subpath(subpath, 1.0); let rotation = PI / 6.0; @@ -415,7 +415,7 @@ mod tests { #[test] fn test_click_target_skew_bypass_cache() { - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::new(100.0, 50.0)); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100.0, 50.0)); let click_target = ClickTarget::new_with_subpath(subpath.clone(), 1.0); // Create a transform with skew (non-uniform scaling in different directions) @@ -431,7 +431,7 @@ mod tests { #[test] fn test_cache_fingerprint_collision_handling() { let mut cache = BoundingBoxCache::default(); - let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::new(10.0, 10.0)); + let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(10.0, 10.0)); let scale = DVec2::ONE; let translation = DVec2::ZERO; diff --git a/node-graph/libraries/vector-types/src/vector/vector_modification.rs b/node-graph/libraries/vector-types/src/vector/vector_modification.rs index e6150c8099..8af9cd8b9e 100644 --- a/node-graph/libraries/vector-types/src/vector/vector_modification.rs +++ b/node-graph/libraries/vector-types/src/vector/vector_modification.rs @@ -654,7 +654,7 @@ mod tests { #[test] fn modify_new() { - let vector: Vector<()> = Vector::from_subpaths([Subpath::new_ellipse(DVec2::ZERO, DVec2::ONE), Subpath::new_rect(DVec2::NEG_ONE, DVec2::ZERO)], false); + let vector: Vector<()> = Vector::from_subpaths([Subpath::new_ellipse(DVec2::ZERO, DVec2::ONE), Subpath::new_rectangle(DVec2::NEG_ONE, DVec2::ZERO)], false); let modify = VectorModification::create_from_vector(&vector); @@ -667,7 +667,7 @@ mod tests { fn modify_existing() { let subpaths = [ Subpath::new_ellipse(DVec2::ZERO, DVec2::ONE), - Subpath::new_rect(DVec2::NEG_ONE, DVec2::ZERO), + Subpath::new_rectangle(DVec2::NEG_ONE, DVec2::ZERO), Subpath::from_beziers( &[ PathSeg::Quad(QuadBez::new(Point::new(0., 0.), Point::new(5., 10.), Point::new(10., 0.))), diff --git a/node-graph/nodes/path-bool/src/lib.rs b/node-graph/nodes/path-bool/src/lib.rs index 2507673da4..0e862f243c 100644 --- a/node-graph/nodes/path-bool/src/lib.rs +++ b/node-graph/nodes/path-bool/src/lib.rs @@ -249,7 +249,7 @@ fn flatten_vector(graphic_table: &Table) -> Table { Graphic::RasterCPU(image) => { let make_row = |transform| { // Convert the image frame into a rectangular subpath with the image's transform - let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE); + let mut subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::ONE); subpath.apply_transform(transform); // Create a vector table row from the rectangular subpath, with a default black fill @@ -265,7 +265,7 @@ fn flatten_vector(graphic_table: &Table) -> Table { Graphic::RasterGPU(image) => { let make_row = |transform| { // Convert the image frame into a rectangular subpath with the image's transform - let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE); + let mut subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::ONE); subpath.apply_transform(transform); // Create a vector table row from the rectangular subpath, with a default black fill diff --git a/node-graph/nodes/vector/src/generator_nodes.rs b/node-graph/nodes/vector/src/generator_nodes.rs index df587528ef..361b6dd8fb 100644 --- a/node-graph/nodes/vector/src/generator_nodes.rs +++ b/node-graph/nodes/vector/src/generator_nodes.rs @@ -14,7 +14,7 @@ trait CornerRadius { impl CornerRadius for f64 { fn generate(self, size: DVec2, clamped: bool) -> Table { let clamped_radius = if clamped { self.clamp(0., size.x.min(size.y).max(0.) / 2.) } else { self }; - Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_rounded_rect(size / -2., size / 2., [clamped_radius; 4]))) + Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_rounded_rectangle(size / -2., size / 2., [clamped_radius; 4]))) } } impl CornerRadius for [f64; 4] { @@ -34,7 +34,7 @@ impl CornerRadius for [f64; 4] { } else { self }; - Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_rounded_rect(size / -2., size / 2., clamped_radius))) + Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_rounded_rectangle(size / -2., size / 2., clamped_radius))) } } diff --git a/node-graph/nodes/vector/src/instance.rs b/node-graph/nodes/vector/src/instance.rs index b57eb48b25..f80a7fb54f 100644 --- a/node-graph/nodes/vector/src/instance.rs +++ b/node-graph/nodes/vector/src/instance.rs @@ -158,7 +158,7 @@ mod test { ); let positions = [DVec2::new(40., 20.), DVec2::ONE, DVec2::new(-42., 9.), DVec2::new(10., 345.)]; - let points = Table::new_from_element(Vector::from_subpath(Subpath::from_anchors_linear(positions, false))); + let points = Table::new_from_element(Vector::from_subpath(Subpath::from_anchors(positions, false))); let generated = super::instance_on_points(owned, points, &rect, false).await; assert_eq!(generated.len(), positions.len()); for (position, generated_row) in positions.into_iter().zip(generated.iter()) {