2016-03-10 23:01:04 +01:00
|
|
|
type Action = () => void;
|
|
|
|
|
|
|
|
namespace helpers {
|
|
|
|
export function arraySplice<T>(arr: T[], start: number, len: number) {
|
|
|
|
if (start < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < len; ++i) {
|
|
|
|
arr.removeAt(start)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace console {
|
|
|
|
export function log(msg: string) {
|
2016-04-02 07:32:33 +02:00
|
|
|
serial.writeString(msg);
|
|
|
|
serial.writeString("\r\n");
|
2016-03-10 23:01:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 07:32:33 +02:00
|
|
|
namespace Math {
|
2016-03-10 23:01:04 +01:00
|
|
|
export function clamp(min: number, max:number, value:number): number {
|
|
|
|
return Math.min(max, Math.max(min, value));
|
|
|
|
}
|
2016-04-02 07:32:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the absolute value of a number (the value without regard to whether it is positive or negative).
|
|
|
|
* For example, the absolute value of -5 is the same as the absolute value of 5.
|
|
|
|
* @param x A numeric expression for which the absolute value is needed.
|
|
|
|
*/
|
|
|
|
export function abs(x: number): number
|
|
|
|
{
|
|
|
|
return x < 0 ? -x : x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the sign of the x, indicating whether x is positive, negative or zero.
|
|
|
|
* @param x The numeric expression to test
|
|
|
|
*/
|
|
|
|
export function sign(x: number): number
|
|
|
|
{
|
|
|
|
if (x == 0) return 0;
|
|
|
|
if (x > 0) return 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the larger of two supplied numeric expressions.
|
|
|
|
*/
|
|
|
|
export function max(a:number, b:number): number
|
|
|
|
{
|
|
|
|
if (a >= b) return a;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the smaller of two supplied numeric expressions.
|
|
|
|
*/
|
|
|
|
export function min(a:number, b:number): number
|
|
|
|
{
|
|
|
|
if (a <= b) return a;
|
|
|
|
return b;
|
|
|
|
}
|
2016-03-10 23:01:04 +01:00
|
|
|
}
|