Comparable

public extension Comparable
  • Normalize a number to a range E.g. 5.normalize(1, 6) will get 5, 5.normalize(1, 3) will get 3, 5.normalize(6, 9) will get 6

    Declaration

    Swift

    func normalize(_ min: Self, _ max: Self) -> Self

    Parameters

    min

    min number

    max

    max number

    Return Value

    number normalized in this range, if self is in the range, self is returned. otherwirse, it will return min or max.

  • Normalize a number to a range in place.

    Declaration

    Swift

    mutating func normalizeInPlace(_ min: Self, _ max: Self)

    Parameters

    min

    min number

    max

    max number

  • Clamp value to the range min…max. This same as normalize(_:_:).

    Declaration

    Swift

    func clamp(to limits: ClosedRange<Self>) -> Self

    Parameters

    limits

    range to clamp

    Return Value

    a value between min … max

  • Clamp self to the range. This same as normalizeInPlace(_:_:).

    Declaration

    Swift

    mutating func clampInPlace(to limits: ClosedRange<Self>)

    Parameters

    limits

    range to clamp