Utilities
This file contains various utility functions.
function Utils.vectorLength(dx,dy)
Calculates the length of the given vector
Parameter
dx
The X component
dy
The Y component
Return: The length as a number.
function Utils.distanceBetween(a,b)
Calculates the distance between two vec2's
FIXME: Should use plain arrays instead of "a.x" etc.
Parameter
a
The first vector
b
The second vector
Return: The distance as a number.
function Utils.angleBetween(a,b,asDegrees)
Calculates the angle (in radians) between an two vectors.
The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
Parameter
a
The first vector as vec2
b
The second vector as vec2
asDegrees
A boolean specifying the return format (degrees vs. radians)
Return: The angle in radians or degrees
function Utils.round(value)
Round a number towards zero
Parameter
value
A number
Return: The rounded number as an integer
function Utils.clamp(value,min,max)
Clamps a number between the given limits
Parameter
value
The value
min
The minimal value
max
The maximal value