Skip to content

Commit abe1e46

Browse files
committed
refactor
1 parent 251691b commit abe1e46

2 files changed

Lines changed: 20 additions & 65 deletions

File tree

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ use crate::messages::tool::common_functionality::graph_modification_utils::{self
2020
use crate::messages::tool::common_functionality::utility_functions::make_path_editable_is_allowed;
2121
use crate::messages::tool::tool_messages::tool_prelude::{Key, MouseMotion};
2222
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
23-
use bezier_rs::Subpath;
2423
use glam::{DAffine2, DVec2, IVec2};
2524
use graph_craft::document::{DocumentNodeImplementation, NodeId, NodeInput};
2625
use graph_craft::proto::GraphErrors;
2726
use graphene_std::math::math_ext::QuadExt;
2827
use graphene_std::vector::algorithms::bezpath_algorithms::bezpath_is_inside_bezpath;
29-
use graphene_std::vector::misc::subpath_to_kurbo_bezpath;
3028
use graphene_std::*;
31-
use kurbo::{DEFAULT_ACCURACY, Line, Point, Shape};
29+
use kurbo::{DEFAULT_ACCURACY, Shape};
3230
use renderer::Quad;
3331
use std::cmp::Ordering;
3432

editor/src/messages/portfolio/document/utility_types/wires.rs

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
2-
use bezier_rs::{ManipulatorGroup, Subpath};
32
use glam::{DVec2, IVec2};
4-
use graphene_std::vector::PointId;
53
use graphene_std::{uuid::NodeId, vector::misc::dvec2_to_point};
6-
use kurbo::{BezPath, Point};
4+
use kurbo::{BezPath, DEFAULT_ACCURACY, Line, Point, Shape};
75

86
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
97
pub struct WirePath {
@@ -93,21 +91,14 @@ pub fn build_vector_wire(output_position: DVec2, input_position: DVec2, vertical
9391
wire.line_to(dvec2_to_point(locations[3]));
9492
wire
9593
}
96-
GraphWireStyle::GridAligned => straight_wire_paths(output_position, input_position, vertical_out, vertical_in)
97-
.iter()
98-
.fold(BezPath::new(), |mut bezpath, point| {
99-
let point = Point::new(point.x as f64, point.y as f64);
100-
if bezpath.elements().is_empty() {
101-
bezpath.move_to(point);
102-
} else {
103-
bezpath.line_to(point);
104-
}
105-
bezpath
106-
}),
94+
GraphWireStyle::GridAligned => {
95+
let locations = straight_wire_path(output_position, input_position, vertical_out, vertical_in);
96+
straight_wire_to_bezpath(locations)
97+
}
10798
}
10899
}
109100

110-
fn straight_wire_paths(output_position: DVec2, input_position: DVec2, vertical_out: bool, vertical_in: bool) -> Vec<IVec2> {
101+
fn straight_wire_path(output_position: DVec2, input_position: DVec2, vertical_out: bool, vertical_in: bool) -> Vec<IVec2> {
111102
let grid_spacing = 24;
112103
let line_width = 2;
113104

@@ -431,40 +422,24 @@ fn straight_wire_paths(output_position: DVec2, input_position: DVec2, vertical_o
431422
vec![IVec2::new(x1, y1), IVec2::new(x20, y1), IVec2::new(x20, y3), IVec2::new(x4, y3)]
432423
}
433424

434-
fn straight_wire_subpath(locations: Vec<IVec2>) -> Subpath<PointId> {
425+
fn straight_wire_to_bezpath(locations: Vec<IVec2>) -> BezPath {
435426
if locations.is_empty() {
436-
return Subpath::new(Vec::new(), false);
427+
return BezPath::new();
437428
}
438429

430+
let to_point = |location: IVec2| Point::new(location.x as f64, location.y as f64);
431+
439432
if locations.len() == 2 {
440-
return Subpath::new(
441-
vec![
442-
ManipulatorGroup {
443-
anchor: locations[0].into(),
444-
in_handle: None,
445-
out_handle: None,
446-
id: PointId::generate(),
447-
},
448-
ManipulatorGroup {
449-
anchor: locations[1].into(),
450-
in_handle: None,
451-
out_handle: None,
452-
id: PointId::generate(),
453-
},
454-
],
455-
false,
456-
);
433+
let p1 = to_point(locations[0]);
434+
let p2 = to_point(locations[1]);
435+
Line::new(p1, p2).to_path(DEFAULT_ACCURACY);
457436
}
458437

459438
let corner_radius = 10;
460439

461440
// Create path with rounded corners
462-
let mut path = vec![ManipulatorGroup {
463-
anchor: locations[0].into(),
464-
in_handle: None,
465-
out_handle: None,
466-
id: PointId::generate(),
467-
}];
441+
let mut path = BezPath::new();
442+
path.move_to(to_point(locations[0]));
468443

469444
for i in 1..(locations.len() - 1) {
470445
let prev = locations[i - 1];
@@ -548,27 +523,9 @@ fn straight_wire_subpath(locations: Vec<IVec2>) -> Subpath<PointId> {
548523
},
549524
);
550525

551-
path.extend(vec![
552-
ManipulatorGroup {
553-
anchor: corner_start.into(),
554-
in_handle: None,
555-
out_handle: Some(corner_start_mid.into()),
556-
id: PointId::generate(),
557-
},
558-
ManipulatorGroup {
559-
anchor: corner_end.into(),
560-
in_handle: Some(corner_end_mid.into()),
561-
out_handle: None,
562-
id: PointId::generate(),
563-
},
564-
])
526+
path.line_to(to_point(corner_start));
527+
path.curve_to(to_point(corner_start_mid), to_point(corner_end_mid), to_point(corner_end));
565528
}
566-
567-
path.push(ManipulatorGroup {
568-
anchor: (*locations.last().unwrap()).into(),
569-
in_handle: None,
570-
out_handle: None,
571-
id: PointId::generate(),
572-
});
573-
Subpath::new(path, false)
529+
path.move_to(to_point(*locations.last().unwrap()));
530+
path
574531
}

0 commit comments

Comments
 (0)