add math utilities
This commit is contained in:
parent
216a077799
commit
f05fa86dbb
@ -82,6 +82,20 @@ function Library (ronin) {
|
|||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.range = (start, end, step = 1) => {
|
||||||
|
let arr = []
|
||||||
|
if (step > 0) {
|
||||||
|
for(let i = start; i <= end ; i+= step) {
|
||||||
|
arr.push(i)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(let i = start; i >= end ; i+= step) {
|
||||||
|
arr.push(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
// Shapes
|
// Shapes
|
||||||
|
|
||||||
this.pos = (x, y, t = 'pos') => {
|
this.pos = (x, y, t = 'pos') => {
|
||||||
@ -179,6 +193,22 @@ function Library (ronin) {
|
|||||||
return Math.round(val / step) * step
|
return Math.round(val / step) * step
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.min = Math.min
|
||||||
|
|
||||||
|
this.max = Math.max
|
||||||
|
|
||||||
|
this.ceil = Math.ceil
|
||||||
|
|
||||||
|
this.floor = Math.floor
|
||||||
|
|
||||||
|
this.sin = Math.sin
|
||||||
|
|
||||||
|
this.cos = Math.cos
|
||||||
|
|
||||||
|
this.PI = Math.PI
|
||||||
|
|
||||||
|
this.TWO_PI = Math.PI
|
||||||
|
|
||||||
// Generics
|
// Generics
|
||||||
|
|
||||||
this.echo = (...args) => {
|
this.echo = (...args) => {
|
||||||
@ -192,11 +222,16 @@ function Library (ronin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.test = (name, a, b) => {
|
this.test = (name, a, b) => {
|
||||||
if (a !== b) {
|
if (Array.isArray(a)) {
|
||||||
|
// TODO: make testing more solid
|
||||||
|
a = a.toString()
|
||||||
|
b = b.toString()
|
||||||
|
}
|
||||||
|
if (a != b) {
|
||||||
console.warn('failed ' + name, a, b)
|
console.warn('failed ' + name, a, b)
|
||||||
} else {
|
} else {
|
||||||
console.log('passed ' + name, a, b)
|
console.log('passed ' + name, a, b)
|
||||||
}
|
}
|
||||||
return a === b
|
return a == b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,7 @@
|
|||||||
|
|
||||||
(test "first" (first ("a" "b" "c")) "a")
|
(test "first" (first ("a" "b" "c")) "a")
|
||||||
(test "last" (last ("a" "b" "c")) "c")
|
(test "last" (last ("a" "b" "c")) "c")
|
||||||
|
(test "range simple" (range 0 4) (0 1 2 3 4))
|
||||||
|
(test "range with step" (range 0 4 2) (0 2 4))
|
||||||
|
(test "range with negative step" (range 0 -4 -1) (0 -1 -2 -3 -4))
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user