Skip to content

Commit 4662cbb

Browse files
committed
Make the 'Count Elements' and 'String Length' nodes return f64 for consistency with 'Instance Index'
1 parent e4d2805 commit 4662cbb

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

node-graph/gcore/src/logic.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ fn string_concatenate(_: impl Ctx, #[implementations(String)] first: String, sec
2828
}
2929

3030
#[node_macro::node(category("Text"))]
31-
fn string_replace(_: impl Ctx, #[implementations(String)] string: String, from: TextArea, to: TextArea) -> String {
31+
fn string_replace(_: impl Ctx, string: String, from: TextArea, to: TextArea) -> String {
3232
string.replace(&from, &to)
3333
}
3434

3535
#[node_macro::node(category("Text"))]
36-
fn string_slice(_: impl Ctx, #[implementations(String)] string: String, start: f64, end: f64) -> String {
36+
fn string_slice(_: impl Ctx, string: String, start: f64, end: f64) -> String {
3737
let start = if start < 0. { string.len() - start.abs() as usize } else { start as usize };
3838
let end = if end <= 0. { string.len() - end.abs() as usize } else { end as usize };
3939
let n = end.saturating_sub(start);
4040
string.char_indices().skip(start).take(n).map(|(_, c)| c).collect()
4141
}
4242

43+
// 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.
44+
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
4345
#[node_macro::node(category("Text"))]
44-
fn string_length(_: impl Ctx, #[implementations(String)] string: String) -> u32 {
45-
string.chars().count() as u32
46+
fn string_length(_: impl Ctx, string: String) -> f64 {
47+
string.chars().count() as f64
4648
}
4749

4850
#[node_macro::node(category("Math: Logic"))]

node-graph/gcore/src/vector/algorithms/instance.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ async fn instance_position(ctx: impl Ctx + ExtractVarArgs) -> DVec2 {
103103
Default::default()
104104
}
105105

106-
// TODO: Make this return a u32 instead of an f64, but we ned to improve math-related compatibility with integer types first.
106+
// 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.
107+
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
107108
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
108109
async fn instance_index(ctx: impl Ctx + ExtractIndex, _primary: (), loop_level: u32) -> f64 {
109110
let Some(index_iter) = ctx.try_index() else { return 0. };

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,9 +1923,11 @@ fn point_inside(_: impl Ctx, source: Table<Vector>, point: DVec2) -> bool {
19231923
source.into_iter().any(|row| row.element.check_point_inside_shape(row.transform, point))
19241924
}
19251925

1926+
// 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.
1927+
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
19261928
#[node_macro::node(category("General"), path(graphene_core::vector))]
1927-
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)] source: Table<I>) -> u64 {
1928-
source.len() as u64
1929+
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)] source: Table<I>) -> f64 {
1930+
source.len() as f64
19291931
}
19301932

19311933
#[node_macro::node(category("Vector: Measure"), path(graphene_core::vector))]

0 commit comments

Comments
 (0)