organise maths helpers

This commit is contained in:
2024-08-22 06:24:30 +10:00
parent b24d154c93
commit cad6418cff
6 changed files with 29 additions and 21 deletions

View File

@ -0,0 +1,10 @@
public extension FloatingPoint {
@inline(__always) var degrees: Self { self * (180 / Self.pi) }
@inline(__always) var radians: Self { self * (Self.pi / 180) }
@inline(__always) func lerp(_ a: Self, _ b: Self) -> Self { b * self + a * (1 - self) }
@inline(__always) func mlerp(_ a: Self, _ b: Self) -> Self { a + (b - a) * self }
@inline(__always) func clamp(_ a: Self, _ b: Self) -> Self { min(max(self, a), b) }
@inline(__always) var saturated: Self { self.clamp(0, 1) }
}