SimpleVector - Interactive examples

back

Clamp methods

The clamp methods all take one or two parameters.

The first parameter is always the maximum bound of the value to clamp.

If a second parameter is provided then it is used as the minimum bound of the value to clamp. If it is not provided, the value is only clamped with the maxium bound.

On this page uncheck the "Enable min bound" checkbox to stop passing a second parameter to the methods.

Clamp magnitude

Enable min bound max bound min bound

v1.clampMag(3, 1.5)

v1
x:0, y:4
v1.clampMag(3, 1.5)
x:0, y:3

Clamp axes

Enable min bound max bound min bound

v1.clampX(2, -2)

v1
x:0, y:4
v1.clampX(2, -2)
x:0, y:4

v1.clampY(2, -2)

v1
x:0, y:4
v1.clampY(2, -2)
x:0, y:2

v1.clampAxes(2, -2)

v1
x:0, y:4
v1.clampAxes(2, -2)
x:0, y:2