diff --git a/node-graph/gcore/src/ops.rs b/node-graph/gcore/src/ops.rs index 2f02b244a8..29f079693f 100644 --- a/node-graph/gcore/src/ops.rs +++ b/node-graph/gcore/src/ops.rs @@ -160,6 +160,18 @@ fn random( result * (max - min) + min } +// To u32 +#[node_macro::node(name("To u32"), category("Math: Numeric"))] +fn to_u32(_: (), #[implementations(f64, f32)] value: U) -> u32 { + value.to_u32().unwrap() +} + +// To u64 +#[node_macro::node(name("To u64"), category("Math: Numeric"))] +fn to_u64(_: (), #[implementations(f64, f32)] value: U) -> u64 { + value.to_u64().unwrap() +} + // Round #[node_macro::node(category("Math: Numeric"))] fn round(_: (), #[implementations(f64, f32)] value: U) -> U { @@ -202,6 +214,23 @@ fn max(_: (), #[implementations(f64, &f64, f32, &f32, } } +// Clamp +#[node_macro::node(category("Math: Numeric"))] +fn clamp( + _: (), + #[implementations(f64, &f64, f32, &f32, u32, &u32, &str)] value: T, + #[implementations(f64, &f64, f32, &f32, u32, &u32, &str)] min: T, + #[implementations(f64, &f64, f32, &f32, u32, &u32, &str)] max: T, +) -> T { + if value < min { + min + } else if value > max { + max + } else { + value + } +} + // Equals #[node_macro::node(category("Math: Logic"))] fn equals, T>(