From 7de13aca3e0fb8e46756d80b67cdc4a5ffb413e4 Mon Sep 17 00:00:00 2001 From: celyk Date: Sun, 6 Jul 2025 19:40:14 +1000 Subject: [PATCH] Make normalize node safer for the user --- node-graph/gmath-nodes/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node-graph/gmath-nodes/src/lib.rs b/node-graph/gmath-nodes/src/lib.rs index f76cba4aa..1019506bd 100644 --- a/node-graph/gmath-nodes/src/lib.rs +++ b/node-graph/gmath-nodes/src/lib.rs @@ -619,9 +619,11 @@ fn length(_: impl Ctx, vector: DVec2) -> f64 { } /// Scales the input vector to unit length while preserving it's direction. This is equivalent to dividing the input vector by it's own magnitude. +/// +/// Returns zero when the input vector is zero. #[node_macro::node(category("Math: Vector"))] fn normalize(_: impl Ctx, vector: DVec2) -> DVec2 { - vector.normalize() + vector.normalize_or_zero() } #[cfg(test)]