|
1 | 1 | use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType; |
2 | | -use bezier_rs::{ManipulatorGroup, Subpath}; |
3 | 2 | use glam::{DVec2, IVec2}; |
4 | | -use graphene_std::vector::PointId; |
5 | 3 | use graphene_std::{uuid::NodeId, vector::misc::dvec2_to_point}; |
6 | | -use kurbo::{BezPath, Point}; |
| 4 | +use kurbo::{BezPath, DEFAULT_ACCURACY, Line, Point, Shape}; |
7 | 5 |
|
8 | 6 | #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)] |
9 | 7 | pub struct WirePath { |
@@ -93,21 +91,14 @@ pub fn build_vector_wire(output_position: DVec2, input_position: DVec2, vertical |
93 | 91 | wire.line_to(dvec2_to_point(locations[3])); |
94 | 92 | wire |
95 | 93 | } |
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 | + } |
107 | 98 | } |
108 | 99 | } |
109 | 100 |
|
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> { |
111 | 102 | let grid_spacing = 24; |
112 | 103 | let line_width = 2; |
113 | 104 |
|
@@ -431,40 +422,24 @@ fn straight_wire_paths(output_position: DVec2, input_position: DVec2, vertical_o |
431 | 422 | vec![IVec2::new(x1, y1), IVec2::new(x20, y1), IVec2::new(x20, y3), IVec2::new(x4, y3)] |
432 | 423 | } |
433 | 424 |
|
434 | | -fn straight_wire_subpath(locations: Vec<IVec2>) -> Subpath<PointId> { |
| 425 | +fn straight_wire_to_bezpath(locations: Vec<IVec2>) -> BezPath { |
435 | 426 | if locations.is_empty() { |
436 | | - return Subpath::new(Vec::new(), false); |
| 427 | + return BezPath::new(); |
437 | 428 | } |
438 | 429 |
|
| 430 | + let to_point = |location: IVec2| Point::new(location.x as f64, location.y as f64); |
| 431 | + |
439 | 432 | 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); |
457 | 436 | } |
458 | 437 |
|
459 | 438 | let corner_radius = 10; |
460 | 439 |
|
461 | 440 | // 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])); |
468 | 443 |
|
469 | 444 | for i in 1..(locations.len() - 1) { |
470 | 445 | let prev = locations[i - 1]; |
@@ -548,27 +523,9 @@ fn straight_wire_subpath(locations: Vec<IVec2>) -> Subpath<PointId> { |
548 | 523 | }, |
549 | 524 | ); |
550 | 525 |
|
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)); |
565 | 528 | } |
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 |
574 | 531 | } |
0 commit comments