New nodes: "Clamp", "To U32", and "To U64" (#2087)

* New nodes: "Clamp", "To U32", and "To U64"

* Add name
This commit is contained in:
Keavon Chambers 2024-11-02 03:20:02 -07:00 committed by GitHub
parent 3f17e83e80
commit 4c9ab2d50b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -160,6 +160,18 @@ fn random<U: num_traits::float::Float>(
result * (max - min) + min
}
// To u32
#[node_macro::node(name("To u32"), category("Math: Numeric"))]
fn to_u32<U: num_traits::float::Float>(_: (), #[implementations(f64, f32)] value: U) -> u32 {
value.to_u32().unwrap()
}
// To u64
#[node_macro::node(name("To u64"), category("Math: Numeric"))]
fn to_u64<U: num_traits::float::Float>(_: (), #[implementations(f64, f32)] value: U) -> u64 {
value.to_u64().unwrap()
}
// Round
#[node_macro::node(category("Math: Numeric"))]
fn round<U: num_traits::float::Float>(_: (), #[implementations(f64, f32)] value: U) -> U {
@ -202,6 +214,23 @@ fn max<T: core::cmp::PartialOrd>(_: (), #[implementations(f64, &f64, f32, &f32,
}
}
// Clamp
#[node_macro::node(category("Math: Numeric"))]
fn clamp<T: core::cmp::PartialOrd>(
_: (),
#[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<U: core::cmp::PartialEq<T>, T>(