Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft commit regarding the splines from point fix #1714

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 28 additions & 7 deletions node-graph/gcore/src/vector/vector_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,36 @@ pub struct SplinesFromPointsNode;

#[node_macro::node_fn(SplinesFromPointsNode)]
fn splines_from_points(mut vector_data: VectorData) -> VectorData {
for subpath in &mut vector_data.subpaths {
let mut spline = Subpath::new_cubic_spline(subpath.anchors());
let points = &vector_data.point_domain;

// Preserve the manipulator group ids
for (spline_manipulator_group, original_manipulator_group) in spline.manipulator_groups_mut().iter_mut().zip(subpath.manipulator_groups()) {
spline_manipulator_group.id = original_manipulator_group.id;
}
vector_data.segment_domain.clear();

let first_handles = bezier_rs::solve_spline_first_handle(points.positions());

*subpath = spline;
for (start_index, end_index) in (0..(points.positions().len())).zip(1..(points.positions().len())) {
let handle_start = first_handles[start_index];
let handle_end = points.positions()[end_index] * 2. - first_handles[end_index];
let handles = bezier_rs::BezierHandles::Cubic { handle_start, handle_end };

vector_data
.segment_domain
.push(SegmentId::generate(), points.ids()[start_index], points.ids()[end_index], handles, StrokeId::generate())
}
let start_points = vector_data.segment_domain.start_point.iter();
let end_points = vector_data.segment_domain.end_point.iter();
let first_point = points.ids().iter().next();
let last_point = points.ids().iter().last();
let closed = start_points
.zip(end_points)
.any(|(first, last)| (first == first_point && last == last_point) || (first == last_point && last == first_point));
if closed {
let handle_start = first_handles[start_index];
let handle_end = points.positions()[end_index] * 2. - first_handles[end_index];
let handles = bezier_rs::BezierHandles::Cubic { handle_start, handle_end };

vector_data
.segment_domain
.push(SegmentId::generate(), points.ids()[start_index], points.ids()[end_index], handles, StrokeId::generate())
}

vector_data
Expand Down