mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 07:08:12 +08:00
Fix the Spline node to maintain stable segment IDs (#3321)
Stable segment ids in the spline node
This commit is contained in:
@@ -821,16 +821,17 @@ async fn vec2_to_point(_: impl Ctx, vec2: DVec2) -> Table<Vector> {
|
|||||||
async fn points_to_polyline(_: impl Ctx, mut points: Table<Vector>, #[default(true)] closed: bool) -> Table<Vector> {
|
async fn points_to_polyline(_: impl Ctx, mut points: Table<Vector>, #[default(true)] closed: bool) -> Table<Vector> {
|
||||||
for row in points.iter_mut() {
|
for row in points.iter_mut() {
|
||||||
let mut segment_domain = SegmentDomain::new();
|
let mut segment_domain = SegmentDomain::new();
|
||||||
|
let mut next_id = SegmentId::ZERO;
|
||||||
|
|
||||||
let points_count = row.element.point_domain.ids().len();
|
let points_count = row.element.point_domain.ids().len();
|
||||||
|
|
||||||
if points_count > 2 {
|
if points_count > 2 {
|
||||||
(0..points_count - 1).for_each(|i| {
|
(0..points_count - 1).for_each(|i| {
|
||||||
segment_domain.push(SegmentId::generate(), i, i + 1, BezierHandles::Linear, StrokeId::generate());
|
segment_domain.push(next_id.next_id(), i, i + 1, BezierHandles::Linear, StrokeId::generate());
|
||||||
});
|
});
|
||||||
|
|
||||||
if closed {
|
if closed {
|
||||||
segment_domain.push(SegmentId::generate(), points_count - 1, 0, BezierHandles::Linear, StrokeId::generate());
|
segment_domain.push(next_id.next_id(), points_count - 1, 0, BezierHandles::Linear, StrokeId::generate());
|
||||||
|
|
||||||
row.element
|
row.element
|
||||||
.region_domain
|
.region_domain
|
||||||
@@ -1394,6 +1395,7 @@ async fn spline(_: impl Ctx, content: Table<Vector>) -> Table<Vector> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut segment_domain = SegmentDomain::default();
|
let mut segment_domain = SegmentDomain::default();
|
||||||
|
let mut next_id = SegmentId::ZERO;
|
||||||
for (manipulator_groups, closed) in row.element.stroke_manipulator_groups() {
|
for (manipulator_groups, closed) in row.element.stroke_manipulator_groups() {
|
||||||
let positions = manipulator_groups.iter().map(|manipulators| manipulators.anchor).collect::<Vec<_>>();
|
let positions = manipulator_groups.iter().map(|manipulators| manipulators.anchor).collect::<Vec<_>>();
|
||||||
let closed = closed && positions.len() > 2;
|
let closed = closed && positions.len() > 2;
|
||||||
@@ -1418,7 +1420,7 @@ async fn spline(_: impl Ctx, content: Table<Vector>) -> Table<Vector> {
|
|||||||
let handle_end = positions[next_index] * 2. - first_handles[next_index];
|
let handle_end = positions[next_index] * 2. - first_handles[next_index];
|
||||||
let handles = BezierHandles::Cubic { handle_start, handle_end };
|
let handles = BezierHandles::Cubic { handle_start, handle_end };
|
||||||
|
|
||||||
segment_domain.push(SegmentId::generate(), start_index, end_index, handles, stroke_id);
|
segment_domain.push(next_id.next_id(), start_index, end_index, handles, stroke_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user