Skip to content

Commit d649052

Browse files
committed
Upgrade and document the math operation nodes
1 parent de366f9 commit d649052

File tree

5 files changed

+148
-62
lines changed

5 files changed

+148
-62
lines changed

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,21 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
559559
.set_input(&InputConnector::node(*node_id, 5), NodeInput::value(TaggedValue::F64(1.), false), &[]);
560560
}
561561

562+
// Upgrade Sine, Cosine, and Tangent nodes to include a boolean input for whether the output should be in radians, which was previously the only option but is now not the default
563+
// Also upgrade the Modulo node to include a boolean input for whether the output should be always positive, which was previously not an option
564+
if (reference == "Sine" || reference == "Cosine" || reference == "Tangent" || reference == "Modulo") && inputs_count == 1 {
565+
let node_definition = resolve_document_node_type(reference).unwrap();
566+
let document_node = node_definition.default_node_template().document_node;
567+
document.network_interface.replace_implementation(node_id, &[], document_node.implementation.clone());
568+
569+
let old_inputs = document.network_interface.replace_inputs(node_id, document_node.inputs.clone(), &[]);
570+
571+
document.network_interface.set_input(&InputConnector::node(*node_id, 0), old_inputs[0].clone(), &[]);
572+
document
573+
.network_interface
574+
.set_input(&InputConnector::node(*node_id, 1), NodeInput::value(TaggedValue::Bool(reference != "Modulo"), false), &[]);
575+
}
576+
562577
// Upgrade layer implementation from https://github.com/GraphiteEditor/Graphite/pull/1946
563578
if reference == "Merge" || reference == "Artboard" {
564579
let node_definition = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type(reference).unwrap();

frontend/src/components/views/Graph.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
style:--data-color-dim={`var(--color-data-${(node.primaryOutput?.dataType || "General").toLowerCase()}-dim)`}
477477
style:--layer-area-width={layerAreaWidth}
478478
style:--node-chain-area-left-extension={layerChainWidth !== 0 ? layerChainWidth + 0.5 : 0}
479-
title={description + (editor.handle.inDevelopmentMode() ? `\n\nNode ID: ${node.id}` : "")}
479+
title={`${node.displayName}\n\n${description || ""}`.trim() + (editor.handle.inDevelopmentMode() ? `\n\nNode ID: ${node.id}` : "")}
480480
data-node={node.id}
481481
bind:this={nodeElements[nodeIndex]}
482482
>
@@ -616,7 +616,7 @@
616616
style:--clip-path-id={`url(#${clipPathId})`}
617617
style:--data-color={`var(--color-data-${(node.primaryOutput?.dataType || "General").toLowerCase()})`}
618618
style:--data-color-dim={`var(--color-data-${(node.primaryOutput?.dataType || "General").toLowerCase()}-dim)`}
619-
title={description + (editor.handle.inDevelopmentMode() ? `\n\nNode ID: ${node.id}` : "")}
619+
title={`${node.displayName}\n\n${description || ""}`.trim() + (editor.handle.inDevelopmentMode() ? `\n\nNode ID: ${node.id}` : "")}
620620
data-node={node.id}
621621
bind:this={nodeElements[nodeIndex]}
622622
>

libraries/bezier-rs/src/subpath/core.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,15 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
366366
}
367367
}
368368

369+
/// Solve for the first handle of an open spline. (The opposite handle can be found by mirroring the result about the anchor.)
369370
pub fn solve_spline_first_handle_open(points: &[DVec2]) -> Vec<DVec2> {
370371
let len_points = points.len();
371372
if len_points == 0 {
372373
return Vec::new();
373374
}
375+
if len_points == 1 {
376+
return vec![points[0]];
377+
}
374378

375379
// Matrix coefficients a, b and c (see https://mathworld.wolfram.com/CubicSpline.html).
376380
// Because the `a` coefficients are all 1, they need not be stored.
@@ -418,6 +422,8 @@ pub fn solve_spline_first_handle_open(points: &[DVec2]) -> Vec<DVec2> {
418422
d
419423
}
420424

425+
/// Solve for the first handle of a closed spline. (The opposite handle can be found by mirroring the result about the anchor.)
426+
/// If called with fewer than 3 points, this function will return an empty result.
421427
pub fn solve_spline_first_handle_closed(points: &[DVec2]) -> Vec<DVec2> {
422428
let len_points = points.len();
423429
if len_points < 3 {

0 commit comments

Comments
 (0)