Functions

The following functions are available globally.

  • Declaration

    Swift

    public func rubberband(value: CGFloat, range: ClosedRange<CGFloat>, interval: CGFloat, c: CGFloat = 0.55) -> CGFloat
  • Projects a scalar value based on a scalar velocity.

    Declaration

    Swift

    public func project(value: CGFloat, velocity: CGFloat, decelerationRate: CGFloat = 0.998) -> CGFloat
  • Projects a 2D point based on a 2D velocity.

    Declaration

    Swift

    public func project(point: CGPoint, velocity: CGPoint, decelerationRate: CGFloat = 0.998) -> CGPoint
  • Takes a value in range (a, b) and returns that value mapped to another range (c, d) using linear interpolation.

    For example, 0.5 mapped from range (0, 1) to range (0, 100) would produce 50.

    Note that the return value is not clipped to the out range. For example, mapRange(2, 0, 1, 0, 100) would return 200.

    Declaration

    Swift

    public func mapRange<T>(value: T, inMin: T, inMax: T, outMin: T, outMax: T, clip: Bool = false) -> T where T : FloatingPoint
  • The same function as mapRange(value:inMin:inMax:outMin:outMax:) but omitting the parameter names for terseness.

    Declaration

    Swift

    public func mapRange<T>(_ value: T, _ inMin: T, _ inMax: T, _ outMin: T, _ outMax: T, clip: Bool = false) -> T where T : FloatingPoint
  • Returns a value bounded by the provided range.

    Declaration

    Swift

    public func clip<T>(value: T, lower: T, upper: T) -> T where T : FloatingPoint

    Parameters

    lower

    The minimum allowable value (inclusive).

    upper

    The maximum allowable value (inclusive).

  • Returns a value bounded by the range [0, 1].

    Declaration

    Swift

    public func clipUnit<T>(value: T) -> T where T : FloatingPoint