Global Function

constrain()

Declaration

func constrain(value: Double, min: Double, max: Double) -> Double

Parameters

value The input value that will be constrained.
min The lower bound, value cannot fall below this value.
max The upper bound, value cannot exceed this value.

Returns

Double - Constrained value.

Description

Limit a value to be inside a range between a minimum and maximum value. If the value is less than the min value, the output value is the min value. If the value is greater than the max value, the output value is the max value.

Examples

brightness = constrain(value: brightness, min: 0.0, max: 255.0)

Related