Skip to content

Commit 79b4f4d

Browse files
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>
1 parent 1264ea8 commit 79b4f4d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

node-graph/gcore/src/ops.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ fn clone<'i, T: Clone + 'i>(_: (), #[implementations(&ImageFrame<Color>)] value:
408408
value.clone()
409409
}
410410

411+
#[node_macro::node(category("Math: Vector"))]
412+
fn dot_product(vector_a: DVec2, vector_b: DVec2) -> f64 {
413+
vector_a.dot(vector_b)
414+
}
415+
411416
// TODO: Rename to "Passthrough"
412417
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
413418
#[node_macro::node(skip_impl)]
@@ -471,9 +476,17 @@ mod test {
471476
let value = ValueNode(4u32).then(IdentityNode::new());
472477
assert_eq!(value.eval(()), &4);
473478
}
479+
474480
#[test]
475481
pub fn foo() {
476482
let fnn = FnNode::new(|(a, b)| (b, a));
477483
assert_eq!(fnn.eval((1u32, 2u32)), (2, 1));
478484
}
485+
486+
#[test]
487+
pub fn dot_product_function() {
488+
let vector_a = glam::DVec2::new(1., 2.);
489+
let vector_b = glam::DVec2::new(3., 4.);
490+
assert_eq!(dot_product(vector_a, vector_b), 11.);
491+
}
479492
}

0 commit comments

Comments
 (0)