FloatingPoint

extension FloatingPoint
  • Range mapping

    Declaration

    Swift

    public func scaled(from source: ClosedRange<Self>,
                       to destination: ClosedRange<Self>,
                       clamped: Bool = false,
                       reversed: Bool = false) -> Self

    Parameters

    source

    source range

    destination

    destination range

    clamped

    specify true to clamp result in destination range

    reversed

    specify true to reverse result

    Return Value

    By mapping source range to destination, result goes from destination lower bound, to destination upper bound once the phase hits source upper bound

Projection

  • Distance travelled after decelerating to zero velocity at a constant rate

    Declaration

    Swift

    public func project(initialVelocity: Self, decelerationRate: Self) -> Self

    Parameters

    initialVelocity

    the velocity at the moment the touch was released

    decelerationRate

    a value that determines the rate of deceleration after the user lifts their finger

    Return Value

    the projection