Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions node-graph/nodes/math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,26 @@ fn clamp<T: std::cmp::PartialOrd>(
}
}

/// Performs smooth Hermite interpolation between two values.
#[node_macro::node(category("Math: Numeric"))]
fn smoothstep<T: num_traits::float::Float>(
_: impl Ctx,
/// The value to be mapped, which is restricted to the range between the minimum and maximum values.
#[implementations(f64, f32)]
value: T,
/// The lower bound of the input range. Input values below this edge are mapped to 0.
#[implementations(f64, f32)]
#[default(0.)]
edge_min: T,
/// The upper bound of the input range. Input values above this edge are mapped to 0.
Comment thread
benstockil marked this conversation as resolved.
Outdated
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
#[implementations(f64, f32)]
#[default(1.)]
edge_max: T,
) -> T {
let t = ((value - edge_min) / (edge_max - edge_min)).clamp(T::zero(), T::one());
t * t * (T::from(3.0).unwrap() - T::from(2.0).unwrap() * t)
Comment thread
benstockil marked this conversation as resolved.
Outdated
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
}

/// The greatest common divisor (GCD) calculates the largest positive integer that divides both of the two input numbers without leaving a remainder.
Comment on lines +571 to 593

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: smoothstep is hardcoded to f64 instead of being generic over Float with #[implementations(f64, f32)], creating inconsistency with adjacent math nodes and limiting graph type interoperability.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/nodes/math/src/lib.rs, line 571:

<comment>`smoothstep` is hardcoded to `f64` instead of being generic over `Float` with `#[implementations(f64, f32)]`, creating inconsistency with adjacent math nodes and limiting graph type interoperability.</comment>

<file context>
@@ -566,6 +566,30 @@ fn clamp<T: std::cmp::PartialOrd>(
 
+/// Performs smooth Hermite interpolation between two values.
+#[node_macro::node(category("Math: Numeric"))]
+fn smoothstep(
+	_: impl Ctx,
+	/// The value to be mapped, which is restricted to the range between the minimum and maximum values.
</file context>
Suggested change
fn smoothstep(
_: impl Ctx,
/// The value to be mapped, which is restricted to the range between the minimum and maximum values.
value: f64,
/// The lower bound of the input range. Input values below this edge are mapped to 0.
#[default(0.)]
edge_min: f64,
/// The upper bound of the input range. Input values above this edge are mapped to 1.
#[default(1.)]
edge_max: f64,
) -> f64 {
let divisor = edge_max - edge_min;
// handle divison by zero
if divisor.abs() == 0.0 {
return if value < edge_min { 0.0 } else { 1.0 };
}
let t = ((value - edge_min) / divisor).clamp(0.0, 1.0);
t * t * (3.0 - 2.0 * t)
}
/// The greatest common divisor (GCD) calculates the largest positive integer that divides both of the two input numbers without leaving a remainder.
fn smoothstep<T: num_traits::float::Float>(
_: impl Ctx,
/// The value to be mapped, which is restricted to the range between the minimum and maximum values.
#[implementations(f64, f32)]
value: T,
/// The lower bound of the input range. Input values below this edge are mapped to 0.
#[implementations(f64, f32)]
#[default(0.)]
edge_min: T,
/// The upper bound of the input range. Input values above this edge are mapped to 1.
#[implementations(f64, f32)]
#[default(1.)]
edge_max: T,
) -> T {
let divisor = edge_max - edge_min;
// handle division by zero
if divisor.abs() < T::epsilon() {
return if value < edge_min { T::zero() } else { T::one() };
}
let t = ((value - edge_min) / divisor).max(T::zero()).min(T::one());
t * t * (T::from(3.0).unwrap() - T::from(2.0).unwrap() * t)
}

#[node_macro::node(category("Math: Numeric"))]
fn greatest_common_divisor<T: num_traits::int::PrimInt + std::ops::ShrAssign<i32> + std::ops::SubAssign>(
Expand Down