Skip to main content

rapier2d/utils/
component_mul.rs

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