Add vector length node

This commit is contained in:
celyk 2025-07-06 18:15:27 +10:00
parent 49db963ce1
commit 3482c5b8a5

View file

@ -612,6 +612,11 @@ fn dot_product(_: impl Ctx, vector_a: DVec2, vector_b: DVec2) -> f64 {
vector_a.dot(vector_b)
}
#[node_macro::node(category("Math: Vector"))]
fn length(_: impl Ctx, vector: DVec2) -> f64 {
vector.length()
}
#[cfg(test)]
mod test {
use super::*;
@ -625,6 +630,12 @@ mod test {
assert_eq!(dot_product((), vector_a, vector_b), 11.);
}
#[test]
pub fn length_function() {
let vector = DVec2::new(3., 4.);
assert_eq!(length((), vector), 5.);
}
#[test]
fn test_basic_expression() {
let result = math((), 0., "2 + 2".to_string(), 0.);