Rename the nodes 'Length' -> 'Magnitude', 'Flatten Path' -> 'Combine Paths', 'Vec2 Value' -> 'Combine Vec2', and add a new 'Vec2 Value' node (#4349)

* Rename the node 'Length' -> 'Magnitude'

* Rename the node 'Flatten Path' -> 'Combine Paths'

* Replace the node 'Vec2 Value' with 'Combine Vec2' and add a new 'Vec2 Value' that's actually a vec2

* Update demo artwork
This commit is contained in:
Keavon Chambers
2026-07-17 09:43:04 -07:00
committed by Dennis Kobert
parent 9556904aed
commit 4f49c000e8
14 changed files with 73 additions and 40 deletions

View File

@@ -42,9 +42,9 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, Vec<RegistryEntry>> {
);
// The path flattening's plain vector rows, served under its identifier.
node_types.extend(
graphene_std::vector::flatten_path_vector_entries()
graphene_std::vector::combine_paths_vector_entries()
.into_iter()
.map(|entry| (graphene_std::vector::flatten_path::IDENTIFIER.clone(), entry)),
.map(|entry| (graphene_std::vector::combine_paths::IDENTIFIER.clone(), entry)),
);
// The solidify's plain vector rows, served under its identifier.
node_types.extend(

View File

@@ -1830,7 +1830,7 @@ fn collect_vector_metadata<S: LaneSource<Element = Vector>>(source: &S, metadata
}
// If this item carries a snapshot of upstream graphic content (e.g. it was produced by Boolean Operation,
// Flatten Path, Morph, or any other destructive merge), recurse into that snapshot so the editor can
// Combine Paths, Morph, or any other destructive merge), recurse into that snapshot so the editor can
// surface the original child layers' click targets.
if let Some(upstream_nested_layers) = source.attr::<EditorMergedLayers>(index).filter(|layers| !layers.is_empty()) {
let mut upstream_footprint = footprint;

View File

@@ -4,7 +4,7 @@ use glam::{DVec2, IVec2, UVec2};
/// Obtains the X or Y component of a vec2.
///
/// The inverse of this node is "Vec2 Value", which can have either or both its X and Y parameters exposed as graph inputs.
/// The inverse of this node is **Combine Vec2**, which composes a vec2 from its X and Y components.
#[node_macro::node(name("Extract XY"), category("Math: Vector"))]
fn extract_xy<T: Into<DVec2>>(_: impl Ctx, #[implementations(DVec2, IVec2, UVec2)] vector: T, axis: XY) -> f64 {
match axis {

View File

@@ -399,7 +399,7 @@ fn vector_row_count(level: GraphicLevel<'_>) -> usize {
// TODO: Flattening erases the upstream `Graphic` hierarchy that editor metadata collection walks to populate
// TODO: `upstream_footprints` / `local_transforms` / `click_targets` per child layer, so the pre-flattened list
// TODO: is stashed on row 0 for `collect_metadata` to recurse into (as Boolean Operation, Solidify Stroke,
// TODO: Flatten Path, Morph and Rasterize do). Driving each layer's metadata from its own Monitor's captured
// TODO: Combine Paths, Morph and Rasterize do). Driving each layer's metadata from its own Monitor's captured
// TODO: `(Context, List<Graphic>)` would make this attribute unnecessary.
/// The parked merged-layers snapshot for row 0. Row 0 carries a composed
/// transform the snapshot's own transforms already include, so the snapshot is

View File

@@ -802,8 +802,8 @@ fn percentage_value(_: impl Ctx, _primary: (), percentage: Percentage) -> f64 {
/// Constructs a two-dimensional vector value which may be set to any XY pair.
#[node_macro::node(category("Value"), name("Vec2 Value"))]
fn vec2_value(_: impl Ctx, _primary: (), x: f64, y: f64) -> DVec2 {
DVec2::new(x, y)
fn vec2_value(_: impl Ctx, _primary: (), #[name("Vec2")] vec2: DVec2) -> DVec2 {
vec2
}
/// Constructs a color value which may be set to any color.
@@ -896,6 +896,23 @@ fn footprint_value(_: impl Ctx, _primary: (), transform: DAffine2, #[default(100
}
}
/// Composes a vec2 from its X and Y components.
///
/// The inverse of this node is **Split Vec2**, which decomposes a vec2 back into its X and Y components.
#[node_macro::node(category("Math: Vector"), name("Combine Vec2"))]
fn combine_vec2(
_: impl Ctx,
_primary: (),
/// The X component of the vec2.
#[expose]
x: f64,
/// The Y component of the vec2.
#[expose]
y: f64,
) -> DVec2 {
DVec2::new(x, y)
}
/// The dot product operation (`·`) calculates the degree of similarity of a vec2 pair based on their angles and lengths.
///
/// Calculated as `‖a‖‖b‖cos(θ)`, it represents the product of their lengths (`‖a‖‖b‖`) scaled by the alignment of their directions (`cos(θ)`).
@@ -964,10 +981,9 @@ fn angle_to<T: ToPosition, U: ToPosition>(
if radians { angle } else { angle.to_degrees() }
}
// TODO: Rename to "Magnitude"
/// The magnitude operator (`‖x‖`) calculates the length of a vec2, which is the distance from the base to the tip of the arrow represented by the vector.
#[node_macro::node(category("Math: Vector"))]
fn length(_: impl Ctx, vector: DVec2) -> f64 {
fn magnitude(_: impl Ctx, vector: DVec2) -> f64 {
vector.length()
}
@@ -991,9 +1007,9 @@ mod test {
}
#[test]
pub fn length_function() {
pub fn magnitude_function() {
let vector = DVec2::new(3., 4.);
assert_eq!(length(&(), vector), 5.);
assert_eq!(magnitude(&(), vector), 5.);
}
#[test]

View File

@@ -2057,9 +2057,9 @@ fn flatten_path_core<'e>(
))
}
// TODO: Rename to "Combine Paths" and make this happen per-element instead of flattening every element into a single path. The migration for this should then become a Flatten Vector -> Combine Paths pair of nodes.
// TODO: Make this happen per-element instead of flattening every element into a single path. The migration for this should then become a Flatten Vector -> Combine Paths pair of nodes.
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
pub fn flatten_path<'e>(
pub fn combine_paths<'e>(
ctx: impl Ctx + ExtractArena<'e> + ExtractIndex + InjectIndex + Copy,
content: IList<Graphic<'static>>,
) -> Result<
@@ -2087,10 +2087,10 @@ pub fn flatten_path<'e>(
Ok((content.lane(carrier).map_element(element), transform, fill, stroke, layer_path, merged))
}
/// The path flattening over a plain vector level, as [`flatten_path`].
/// Registered under the flatten path identifier.
/// The path flattening over a plain vector level, as [`combine_paths`].
/// Registered under the combine paths identifier.
#[node_macro::node(category(""))]
pub fn flatten_path_vector<'e>(
pub fn combine_paths_vector<'e>(
ctx: impl Ctx + ExtractArena<'e> + ExtractIndex + InjectIndex + Copy,
content: IList<Vector>,
) -> Result<
@@ -2118,7 +2118,7 @@ pub fn flatten_path_vector<'e>(
Ok((content.lane(carrier).map_element(element), transform, fill, stroke, layer_path, merged))
}
pub use _flatten_path_vector_mod::flatten_path_vector_entries;
pub use _combine_paths_vector_mod::combine_paths_vector_entries;
/// Convert vector geometry into a polyline composed of evenly spaced points.
#[node_macro::node(category("Vector: Modifier"), path(core_types::vector), properties("sample_polyline_properties"), memoize)]
@@ -4137,6 +4137,7 @@ mod test {
assert_eq!(manipulator_groups_anchors[i], expected_bounding_box[i]);
}
}
#[test]
fn sample_polyline() {
let path = BezPath::from_vec(vec![PathEl::MoveTo(Point::ZERO), PathEl::CurveTo(Point::ZERO, Point::new(100., 0.), Point::new(100., 0.))]);