fix wide_dot and wide_length_squared

This commit is contained in:
Quaternions 2024-08-23 16:49:05 -07:00
parent d38d103399
commit 3ccc19f768
2 changed files with 24 additions and 4 deletions

View File

@ -11,15 +11,15 @@ macro_rules! impl_wide_operations {
}
}
}
impl<T:Copy+fixed_wide::wide::WideMul<Output=T>+std::ops::Add<Output=T>> $struct<T> {
impl<U:std::ops::Add<Output=U>,T:Copy+fixed_wide::wide::WideMul<Output=U>> $struct<T> {
#[inline]
pub fn wide_dot(&self, other: &Self) -> <T as fixed_wide::wide::WideMul>::Output {
pub fn wide_dot(self, other: Self) -> U {
$crate::sum_repeating!(
$( + (self.$field.wide_mul(other.$field)) ) +
)
}
pub fn length_squared(&self) -> <T as fixed_wide::wide::WideMul>::Output {
let squared = Self {
pub fn wide_length_squared(&self) -> U {
let squared = $struct {
$( $field: self.$field.wide_mul(self.$field) ), +
};

View File

@ -34,3 +34,23 @@ fn wide_vec3(){
assert_eq!(v3,Vector3::from_value(Planar64Wide3::from(3i128.pow(8))));
}
#[test]
fn wide_vec3_dot(){
let v=Vector3::from_value(Planar64::from(3));
let v1=v.wide_mul(v);
let v2=v1.wide_mul(v1);
let v3=v2.wide_dot(v2);
assert_eq!(v3,Planar64Wide3::from(3i128.pow(8)*3));
}
#[test]
fn wide_vec3_length_squared(){
let v=Vector3::from_value(Planar64::from(3));
let v1=v.wide_mul(v);
let v2=v1.wide_mul(v1);
let v3=v2.wide_length_squared();
assert_eq!(v3,Planar64Wide3::from(3i128.pow(8)*3));
}