Skip to main content

ClampedValue

ClampedValue

A class containing a number, functions to change the value of the number and variables and functions that restrict the range of values the number can hold (aka clamping). Commonly used to set the number of input ports for a component.


Constructor

public ClampedValue

new ClampedValue(initialValue)

Set the initial value for a number to be clamped, minimum and maximum values unspecified.

Parameters

  •  initialValue: number – The inital value of the number.

new ClampedValue(initialValue, minValue, maxValue)

Set the initial value for a number and minimum and maximum values for clamping.

Parameters

  •  initialValue: number – The inital value of the number.

  •  minValue: number – The minimum value the number can hold.

  •  maxValue: number – The maximum value the number can hold.


Properties

No publicly accessible properties on ClampedValue

private value: number

The current clamped value of the number.

private minValue: number

The minimum value the number can hold.

private maxValue: number

The maximum value the number can hold.


Methods

public setValue

setValue(val) => void

Update the number to a new value, or the closest clamp bound if outside allowed range.

Parameters

  •  val: number – The clamped value of the number.

public setMinValue

setMinValue(val) => void

Set the minimum value the number can hold.

Parameters

  •  val: number – The minimum value the number can hold.

public setMaxValue

setMaxValue(val) => void

Set the maximum value the number can hold.

Parameters

  •  val: number – The maximum value the number can hold.

public getValue

getValue() => number

Returns the clamped value of the number.

Returns

  •   number – The clamped value of the number.

public getMinValue

getMinValue() => number

Returns the minimum value the number can hold.

Returns

  •   number – The minimum value the number can hold.

public getMaxValue

getMaxValue() => number

Returns the maximum value the number can hold.

Returns

  •   number – The maximum value the number can hold.

public contains

contains(value) => false | true

Checks whether the supplied value is within the bounds of this clamped value.

Parameters

  •  value: number – The number to evaluate.

Returns

  •   false | true – True if value is between the minimum and maximum allowed values.

public copy

copy() => ClampedValue

Returns a new instance of the ClampedValue object, identical to the original.

Returns

  •   ClampedValue – A new instance of the ClampedValue object, identical to the original.

Static Methods

No static methods for ClampedValue