Skip to content

Commit 7cc4dce

Browse files
authored
Switch to precise lerp. (#548)
Reviving #278, fixes #275.
1 parent 9a8729d commit 7cc4dce

File tree

19 files changed

+37
-16
lines changed

19 files changed

+37
-16
lines changed

codegen/templates/vec.rs.tera

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ impl {{ self_t }} {
18671867
#[inline]
18681868
#[must_use]
18691869
pub fn lerp(self, rhs: Self, s: {{ scalar_t }}) -> Self {
1870-
self + ((rhs - self) * s)
1870+
self * (1.0 - s) + rhs * s
18711871
}
18721872

18731873
/// Moves towards `rhs` based on the value `d`.

src/f32/coresimd/vec3a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ impl Vec3A {
726726
#[inline]
727727
#[must_use]
728728
pub fn lerp(self, rhs: Self, s: f32) -> Self {
729-
self + ((rhs - self) * s)
729+
self * (1.0 - s) + rhs * s
730730
}
731731

732732
/// Moves towards `rhs` based on the value `d`.

src/f32/coresimd/vec4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl Vec4 {
713713
#[inline]
714714
#[must_use]
715715
pub fn lerp(self, rhs: Self, s: f32) -> Self {
716-
self + ((rhs - self) * s)
716+
self * (1.0 - s) + rhs * s
717717
}
718718

719719
/// Moves towards `rhs` based on the value `d`.

src/f32/neon/vec3a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl Vec3A {
770770
#[inline]
771771
#[must_use]
772772
pub fn lerp(self, rhs: Self, s: f32) -> Self {
773-
self + ((rhs - self) * s)
773+
self * (1.0 - s) + rhs * s
774774
}
775775

776776
/// Moves towards `rhs` based on the value `d`.

src/f32/neon/vec4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl Vec4 {
747747
#[inline]
748748
#[must_use]
749749
pub fn lerp(self, rhs: Self, s: f32) -> Self {
750-
self + ((rhs - self) * s)
750+
self * (1.0 - s) + rhs * s
751751
}
752752

753753
/// Moves towards `rhs` based on the value `d`.

src/f32/scalar/vec3a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ impl Vec3A {
769769
#[inline]
770770
#[must_use]
771771
pub fn lerp(self, rhs: Self, s: f32) -> Self {
772-
self + ((rhs - self) * s)
772+
self * (1.0 - s) + rhs * s
773773
}
774774

775775
/// Moves towards `rhs` based on the value `d`.

src/f32/scalar/vec4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ impl Vec4 {
827827
#[inline]
828828
#[must_use]
829829
pub fn lerp(self, rhs: Self, s: f32) -> Self {
830-
self + ((rhs - self) * s)
830+
self * (1.0 - s) + rhs * s
831831
}
832832

833833
/// Moves towards `rhs` based on the value `d`.

src/f32/sse2/vec3a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ impl Vec3A {
769769
#[inline]
770770
#[must_use]
771771
pub fn lerp(self, rhs: Self, s: f32) -> Self {
772-
self + ((rhs - self) * s)
772+
self * (1.0 - s) + rhs * s
773773
}
774774

775775
/// Moves towards `rhs` based on the value `d`.

src/f32/sse2/vec4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ impl Vec4 {
755755
#[inline]
756756
#[must_use]
757757
pub fn lerp(self, rhs: Self, s: f32) -> Self {
758-
self + ((rhs - self) * s)
758+
self * (1.0 - s) + rhs * s
759759
}
760760

761761
/// Moves towards `rhs` based on the value `d`.

src/f32/vec2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ impl Vec2 {
692692
#[inline]
693693
#[must_use]
694694
pub fn lerp(self, rhs: Self, s: f32) -> Self {
695-
self + ((rhs - self) * s)
695+
self * (1.0 - s) + rhs * s
696696
}
697697

698698
/// Moves towards `rhs` based on the value `d`.

0 commit comments

Comments
 (0)