Fix and clean up typing-related flaws with the Math category of nodes

This commit is contained in:
Keavon Chambers
2025-09-18 16:37:01 -07:00
parent 7e3ab78ea4
commit 9d15e56ce1
6 changed files with 112 additions and 96 deletions

View File

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

View File

@@ -9,9 +9,9 @@ use crate::vector::Vector;
use crate::{Context, Ctx};
use glam::{DAffine2, DVec2};
#[node_macro::node(category("Type Conversion"))]
fn to_string<T: std::fmt::Debug>(_: impl Ctx, #[implementations(bool, f64, u32, u64, DVec2, DAffine2, String)] value: T) -> String {
format!("{value:?}")
#[node_macro::node(category("Debug"))]
fn to_string(_: impl Ctx, value: String) -> String {
value
}
#[node_macro::node(category("Text"))]
@@ -34,10 +34,24 @@ fn string_replace(_: impl Ctx, string: String, from: TextArea, to: TextArea) ->
#[node_macro::node(category("Text"))]
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 end = if end <= 0. { string.len() - end.abs() as usize } else { end as usize };
let n = end.saturating_sub(start);
string.char_indices().skip(start).take(n).map(|(_, c)| c).collect()
let total_chars = string.chars().count();
let start = if start < 0. {
total_chars.saturating_sub(start.abs() as usize)
} else {
(start as usize).min(total_chars)
};
let end = if end <= 0. {
total_chars.saturating_sub(end.abs() as usize)
} else {
(end as usize).min(total_chars)
};
if start >= end {
return String::new();
}
string.chars().skip(start).take(end - start).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.

View File

@@ -1,6 +1,5 @@
use graphene_core_shaders::Ctx;
use crate::Node;
use graphene_core_shaders::Ctx;
use std::marker::PhantomData;
// TODO: Rename to "Passthrough"