diff --git a/codegen/templates/vec.rs.tera b/codegen/templates/vec.rs.tera index e8408ff4..b1c1ed6a 100644 --- a/codegen/templates/vec.rs.tera +++ b/codegen/templates/vec.rs.tera @@ -1867,7 +1867,7 @@ impl {{ self_t }} { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: {{ scalar_t }}) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/coresimd/vec3a.rs b/src/f32/coresimd/vec3a.rs index 8d280e0e..cc715f91 100644 --- a/src/f32/coresimd/vec3a.rs +++ b/src/f32/coresimd/vec3a.rs @@ -726,7 +726,7 @@ impl Vec3A { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/coresimd/vec4.rs b/src/f32/coresimd/vec4.rs index 47d0bc60..7876731f 100644 --- a/src/f32/coresimd/vec4.rs +++ b/src/f32/coresimd/vec4.rs @@ -713,7 +713,7 @@ impl Vec4 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/neon/vec3a.rs b/src/f32/neon/vec3a.rs index 5b80cb37..a6e7f9ed 100644 --- a/src/f32/neon/vec3a.rs +++ b/src/f32/neon/vec3a.rs @@ -770,7 +770,7 @@ impl Vec3A { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/neon/vec4.rs b/src/f32/neon/vec4.rs index 1c81ea14..296a3ebd 100644 --- a/src/f32/neon/vec4.rs +++ b/src/f32/neon/vec4.rs @@ -747,7 +747,7 @@ impl Vec4 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/scalar/vec3a.rs b/src/f32/scalar/vec3a.rs index 50a788a1..abc3af03 100644 --- a/src/f32/scalar/vec3a.rs +++ b/src/f32/scalar/vec3a.rs @@ -769,7 +769,7 @@ impl Vec3A { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/scalar/vec4.rs b/src/f32/scalar/vec4.rs index 1afdabdc..68e881cc 100644 --- a/src/f32/scalar/vec4.rs +++ b/src/f32/scalar/vec4.rs @@ -827,7 +827,7 @@ impl Vec4 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/sse2/vec3a.rs b/src/f32/sse2/vec3a.rs index 0f92f52a..62f22bc9 100644 --- a/src/f32/sse2/vec3a.rs +++ b/src/f32/sse2/vec3a.rs @@ -769,7 +769,7 @@ impl Vec3A { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/sse2/vec4.rs b/src/f32/sse2/vec4.rs index c773f68b..afb30e5a 100644 --- a/src/f32/sse2/vec4.rs +++ b/src/f32/sse2/vec4.rs @@ -755,7 +755,7 @@ impl Vec4 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/vec2.rs b/src/f32/vec2.rs index 241774a9..fa2367ca 100644 --- a/src/f32/vec2.rs +++ b/src/f32/vec2.rs @@ -692,7 +692,7 @@ impl Vec2 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/vec3.rs b/src/f32/vec3.rs index b5a5a4f5..2e8df473 100644 --- a/src/f32/vec3.rs +++ b/src/f32/vec3.rs @@ -759,7 +759,7 @@ impl Vec3 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/wasm32/vec3a.rs b/src/f32/wasm32/vec3a.rs index 8d682dda..1c5393a2 100644 --- a/src/f32/wasm32/vec3a.rs +++ b/src/f32/wasm32/vec3a.rs @@ -737,7 +737,7 @@ impl Vec3A { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f32/wasm32/vec4.rs b/src/f32/wasm32/vec4.rs index d5526163..6037a089 100644 --- a/src/f32/wasm32/vec4.rs +++ b/src/f32/wasm32/vec4.rs @@ -730,7 +730,7 @@ impl Vec4 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f32) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f64/dvec2.rs b/src/f64/dvec2.rs index 61aa26d4..25e83fad 100644 --- a/src/f64/dvec2.rs +++ b/src/f64/dvec2.rs @@ -692,7 +692,7 @@ impl DVec2 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f64) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f64/dvec3.rs b/src/f64/dvec3.rs index 5e4b4830..85c69bc4 100644 --- a/src/f64/dvec3.rs +++ b/src/f64/dvec3.rs @@ -759,7 +759,7 @@ impl DVec3 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f64) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/src/f64/dvec4.rs b/src/f64/dvec4.rs index 314a48e1..3444ba31 100644 --- a/src/f64/dvec4.rs +++ b/src/f64/dvec4.rs @@ -816,7 +816,7 @@ impl DVec4 { #[inline] #[must_use] pub fn lerp(self, rhs: Self, s: f64) -> Self { - self + ((rhs - self) * s) + self * (1.0 - s) + rhs * s } /// Moves towards `rhs` based on the value `d`. diff --git a/tests/vec2.rs b/tests/vec2.rs index f16b86f6..197d338d 100644 --- a/tests/vec2.rs +++ b/tests/vec2.rs @@ -843,6 +843,13 @@ macro_rules! impl_vec2_float_tests { assert_approx_eq!($vec2::ZERO, v0.lerp(v1, 0.5)); }); + glam_test!(test_lerp_big_difference, { + let v0 = $vec2::new(-1e30, -1e30); + let v1 = $vec2::new(16.0, 16.0); + assert_approx_eq!(v0, v0.lerp(v1, 0.0)); + assert_approx_eq!(v1, v0.lerp(v1, 1.0)); + }); + glam_test!(test_move_towards, { let v0 = $vec2::new(-1.0, -1.0); let v1 = $vec2::new(1.0, 1.0); diff --git a/tests/vec3.rs b/tests/vec3.rs index 62ce25a5..4957d5a3 100644 --- a/tests/vec3.rs +++ b/tests/vec3.rs @@ -987,6 +987,13 @@ macro_rules! impl_vec3_float_tests { assert_approx_eq!($vec3::ZERO, v0.lerp(v1, 0.5)); }); + glam_test!(test_lerp_big_difference, { + let v0 = $vec3::new(-1e30, -1e30, -1e30); + let v1 = $vec3::new(16.0, 16.0, 16.0); + assert_approx_eq!(v0, v0.lerp(v1, 0.0)); + assert_approx_eq!(v1, v0.lerp(v1, 1.0)); + }); + glam_test!(test_move_towards, { let v0 = $vec3::new(-1.0, -1.0, -1.0); let v1 = $vec3::new(1.0, 1.0, 1.0); diff --git a/tests/vec4.rs b/tests/vec4.rs index 4d36d954..21626a4c 100644 --- a/tests/vec4.rs +++ b/tests/vec4.rs @@ -1124,6 +1124,13 @@ macro_rules! impl_vec4_float_tests { assert_approx_eq!($vec4::ZERO, v0.lerp(v1, 0.5)); }); + glam_test!(test_lerp_big_difference, { + let v0 = $vec4::new(-1e30, -1e30, -1e30, -1e30); + let v1 = $vec4::new(16.0, 16.0, 16.0, 16.0); + assert_approx_eq!(v0, v0.lerp(v1, 0.0)); + assert_approx_eq!(v1, v0.lerp(v1, 1.0)); + }); + glam_test!(test_move_towards, { let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0);