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

View file

@ -408,6 +408,11 @@ fn clone<'i, T: Clone + 'i>(_: (), #[implementations(&ImageFrame<Color>)] value:
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"
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
#[node_macro::node(skip_impl)]
@ -471,9 +476,17 @@ mod test {
let value = ValueNode(4u32).then(IdentityNode::new());
assert_eq!(value.eval(()), &4);
}
#[test]
pub fn foo() {
let fnn = FnNode::new(|(a, b)| (b, a));
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.);
}
}