Add dot product node (#2126)

* dot product node

* dot product node

* cross product node

* formatting n deleted comments

* name changed

* name changed

* cross product removed

* Minor code style changes

---------

Co-authored-by: hypercube <0hypercube@gmail.com>
This commit is contained in:
Gulshan1-3 2024-12-17 01:47:51 +05:30 committed by GitHub
parent 1264ea8246
commit 79b4f4df7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -408,6 +408,11 @@ fn clone<'i, T: Clone + 'i>(_: (), #[implementations(&ImageFrame<Color>)] value:
value.clone() value.clone()
} }
#[node_macro::node(category("Math: Vector"))]
fn dot_product(vector_a: DVec2, vector_b: DVec2) -> f64 {
vector_a.dot(vector_b)
}
// TODO: Rename to "Passthrough" // TODO: Rename to "Passthrough"
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes. /// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
#[node_macro::node(skip_impl)] #[node_macro::node(skip_impl)]
@ -471,9 +476,17 @@ mod test {
let value = ValueNode(4u32).then(IdentityNode::new()); let value = ValueNode(4u32).then(IdentityNode::new());
assert_eq!(value.eval(()), &4); assert_eq!(value.eval(()), &4);
} }
#[test] #[test]
pub fn foo() { pub fn foo() {
let fnn = FnNode::new(|(a, b)| (b, a)); let fnn = FnNode::new(|(a, b)| (b, a));
assert_eq!(fnn.eval((1u32, 2u32)), (2, 1)); assert_eq!(fnn.eval((1u32, 2u32)), (2, 1));
} }
#[test]
pub fn dot_product_function() {
let vector_a = glam::DVec2::new(1., 2.);
let vector_b = glam::DVec2::new(3., 4.);
assert_eq!(dot_product(vector_a, vector_b), 11.);
}
} }