Skip to content

Commit 662691f

Browse files
committed
New node: 'Offset Points'
1 parent 1543d97 commit 662691f

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ async fn jitter_points(
19581958
/// The maximum extent of the random distance each point can be offset.
19591959
#[default(5.)]
19601960
#[unit(" px")]
1961-
amount: f64,
1961+
max_distance: f64,
19621962
/// Seed used to determine unique variations on all randomized offsets.
19631963
seed: SeedValue,
19641964
/// Whether to offset anchor points along their normal direction (perpendicular to the path) or in a random direction. Free-floating and branching points have no normal direction, so they receive a random-angled offset regardless of this setting.
@@ -1974,7 +1974,7 @@ async fn jitter_points(
19741974
let deltas: Vec<_> = (0..row.element.point_domain.positions().len())
19751975
.map(|point_index| {
19761976
let normal = if along_normals {
1977-
row.element.segment_domain.point_tangent(point_index, row.element.point_domain.positions()).map(|t| t.perp())
1977+
row.element.segment_domain.point_tangent(point_index, row.element.point_domain.positions()).map(|t| -t.perp())
19781978
} else {
19791979
None
19801980
};
@@ -1985,7 +1985,41 @@ async fn jitter_points(
19851985
DVec2::from_angle(rng.random::<f64>() * TAU) * rng.random::<f64>()
19861986
};
19871987

1988-
inverse_linear * (offset * amount)
1988+
inverse_linear * offset * max_distance
1989+
})
1990+
.collect();
1991+
1992+
apply_point_deltas(&mut row.element, &deltas, row.transform);
1993+
1994+
row
1995+
})
1996+
.collect()
1997+
}
1998+
1999+
/// Displaces anchor points along their normal direction (perpendicular to the path) by a set distance.
2000+
/// Points with 0 or 3+ segment connections have no well-defined normal and are left in place.
2001+
#[node_macro::node(category("Vector: Modifier"), path(core_types::vector))]
2002+
async fn offset_points(
2003+
_: impl Ctx,
2004+
/// The vector geometry with points to be offset.
2005+
content: Table<Vector>,
2006+
/// The distance to offset each anchor point along its normal. Positive values move outward, negative values move inward.
2007+
#[default(10.)]
2008+
#[unit(" px")]
2009+
distance: f64,
2010+
) -> Table<Vector> {
2011+
content
2012+
.into_iter()
2013+
.map(|mut row| {
2014+
let inverse_linear = inverse_linear_or_repair(row.transform.matrix2);
2015+
2016+
let deltas: Vec<_> = (0..row.element.point_domain.positions().len())
2017+
.map(|point_index| {
2018+
let Some(normal) = row.element.segment_domain.point_tangent(point_index, row.element.point_domain.positions()).map(|t| -t.perp()) else {
2019+
return DVec2::ZERO;
2020+
};
2021+
2022+
inverse_linear * normal * distance
19892023
})
19902024
.collect();
19912025

0 commit comments

Comments
 (0)