Skip to content

Commit 9d15e56

Browse files
committed
Fix and clean up typing-related flaws with the Math category of nodes
1 parent 7e3ab78 commit 9d15e56

File tree

6 files changed

+112
-96
lines changed

6 files changed

+112
-96
lines changed

editor/src/messages/portfolio/document_migration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
10601060
if reference == "Instance Index" && inputs_count == 0 {
10611061
let mut node_template = resolve_document_node_type(reference)?.default_node_template();
10621062
document.network_interface.replace_implementation(node_id, network_path, &mut node_template);
1063+
document.network_interface.set_display_name(node_id, "Instance Index".to_string(), network_path);
10631064

10641065
let mut node_path = network_path.to_vec();
10651066
node_path.push(*node_id);

node-graph/gcore/src/graphic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ async fn wrap_graphic<T: Into<Graphic> + 'n>(
338338

339339
/// Converts a table of graphical content into a graphic table by placing it into an element of a new wrapper graphic table.
340340
/// If it is already a graphic table, it is not wrapped again. Use the 'Wrap Graphic' node if wrapping is always desired.
341-
#[node_macro::node(category("Type Conversion"))]
341+
#[node_macro::node(category("General"))]
342342
async fn to_graphic<T: Into<Table<Graphic>> + 'n>(
343343
_: impl Ctx,
344344
#[implementations(

node-graph/gcore/src/logic.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::vector::Vector;
99
use crate::{Context, Ctx};
1010
use glam::{DAffine2, DVec2};
1111

12-
#[node_macro::node(category("Type Conversion"))]
13-
fn to_string<T: std::fmt::Debug>(_: impl Ctx, #[implementations(bool, f64, u32, u64, DVec2, DAffine2, String)] value: T) -> String {
14-
format!("{value:?}")
12+
#[node_macro::node(category("Debug"))]
13+
fn to_string(_: impl Ctx, value: String) -> String {
14+
value
1515
}
1616

1717
#[node_macro::node(category("Text"))]
@@ -34,10 +34,24 @@ fn string_replace(_: impl Ctx, string: String, from: TextArea, to: TextArea) ->
3434

3535
#[node_macro::node(category("Text"))]
3636
fn string_slice(_: impl Ctx, string: String, start: f64, end: f64) -> String {
37-
let start = if start < 0. { string.len() - start.abs() as usize } else { start as usize };
38-
let end = if end <= 0. { string.len() - end.abs() as usize } else { end as usize };
39-
let n = end.saturating_sub(start);
40-
string.char_indices().skip(start).take(n).map(|(_, c)| c).collect()
37+
let total_chars = string.chars().count();
38+
39+
let start = if start < 0. {
40+
total_chars.saturating_sub(start.abs() as usize)
41+
} else {
42+
(start as usize).min(total_chars)
43+
};
44+
let end = if end <= 0. {
45+
total_chars.saturating_sub(end.abs() as usize)
46+
} else {
47+
(end as usize).min(total_chars)
48+
};
49+
50+
if start >= end {
51+
return String::new();
52+
}
53+
54+
string.chars().skip(start).take(end - start).collect()
4155
}
4256

4357
// TODO: Return u32, u64, or usize instead of f64 after #1621 is resolved and has allowed us to implement automatic type conversion in the node graph for nodes with generic type inputs.

node-graph/gcore/src/ops.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use graphene_core_shaders::Ctx;
2-
31
use crate::Node;
2+
use graphene_core_shaders::Ctx;
43
use std::marker::PhantomData;
54

65
// TODO: Rename to "Passthrough"

0 commit comments

Comments
 (0)