Skip to main content

rapier2d/utils/
component_mul.rs

1//! ComponentMul trait for element-wise vector operations.
2
3use crate::math::Vector;
4use crate::utils::SimdRealCopy;
5use na::{Vector2, Vector3};
6
7/// Extension trait for element-wise vector operations
8pub trait ComponentMul: Sized {
9    /// Element-wise multiplication
10    fn component_mul(&self, other: &Self) -> Self;
11}
12
13impl ComponentMul for Vector {
14    #[inline]
15    fn component_mul(&self, other: &Self) -> Self {
16        *self * *other
17    }
18}
19
20// Nalgebra vector implementations for SIMD support
21impl<N: SimdRealCopy> ComponentMul for Vector2<N> {
22    #[inline]
23    fn component_mul(&self, other: &Self) -> Self {
24        nalgebra::Vector2::component_mul(self, other)
25    }
26}
27
28impl<N: SimdRealCopy> ComponentMul for Vector3<N> {
29    #[inline]
30    fn component_mul(&self, other: &Self) -> Self {
31        nalgebra::Vector3::component_mul(self, other)
32    }
33}