Make the 'Count Elements' and 'String Length' nodes return f64 for consistency with 'Instance Index'
This commit is contained in:
parent
e4d2805115
commit
4662cbbbc1
|
|
@ -28,21 +28,23 @@ fn string_concatenate(_: impl Ctx, #[implementations(String)] first: String, sec
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Text"))]
|
#[node_macro::node(category("Text"))]
|
||||||
fn string_replace(_: impl Ctx, #[implementations(String)] string: String, from: TextArea, to: TextArea) -> String {
|
fn string_replace(_: impl Ctx, string: String, from: TextArea, to: TextArea) -> String {
|
||||||
string.replace(&from, &to)
|
string.replace(&from, &to)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Text"))]
|
#[node_macro::node(category("Text"))]
|
||||||
fn string_slice(_: impl Ctx, #[implementations(String)] string: String, start: f64, end: f64) -> String {
|
fn string_slice(_: impl Ctx, string: String, start: f64, end: f64) -> String {
|
||||||
let start = if start < 0. { string.len() - start.abs() as usize } else { start as usize };
|
let start = if start < 0. { string.len() - start.abs() as usize } else { start as usize };
|
||||||
let end = if end <= 0. { string.len() - end.abs() as usize } else { end as usize };
|
let end = if end <= 0. { string.len() - end.abs() as usize } else { end as usize };
|
||||||
let n = end.saturating_sub(start);
|
let n = end.saturating_sub(start);
|
||||||
string.char_indices().skip(start).take(n).map(|(_, c)| c).collect()
|
string.char_indices().skip(start).take(n).map(|(_, c)| c).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
|
||||||
#[node_macro::node(category("Text"))]
|
#[node_macro::node(category("Text"))]
|
||||||
fn string_length(_: impl Ctx, #[implementations(String)] string: String) -> u32 {
|
fn string_length(_: impl Ctx, string: String) -> f64 {
|
||||||
string.chars().count() as u32
|
string.chars().count() as f64
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Math: Logic"))]
|
#[node_macro::node(category("Math: Logic"))]
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,8 @@ async fn instance_position(ctx: impl Ctx + ExtractVarArgs) -> DVec2 {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this return a u32 instead of an f64, but we ned to improve math-related compatibility with integer types first.
|
// 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.
|
||||||
|
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
|
||||||
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
||||||
async fn instance_index(ctx: impl Ctx + ExtractIndex, _primary: (), loop_level: u32) -> f64 {
|
async fn instance_index(ctx: impl Ctx + ExtractIndex, _primary: (), loop_level: u32) -> f64 {
|
||||||
let Some(index_iter) = ctx.try_index() else { return 0. };
|
let Some(index_iter) = ctx.try_index() else { return 0. };
|
||||||
|
|
|
||||||
|
|
@ -1923,9 +1923,11 @@ fn point_inside(_: impl Ctx, source: Table<Vector>, point: DVec2) -> bool {
|
||||||
source.into_iter().any(|row| row.element.check_point_inside_shape(row.transform, point))
|
source.into_iter().any(|row| row.element.check_point_inside_shape(row.transform, point))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
|
||||||
#[node_macro::node(category("General"), path(graphene_core::vector))]
|
#[node_macro::node(category("General"), path(graphene_core::vector))]
|
||||||
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 {
|
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 {
|
||||||
source.len() as u64
|
source.len() as f64
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Vector: Measure"), path(graphene_core::vector))]
|
#[node_macro::node(category("Vector: Measure"), path(graphene_core::vector))]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue