-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaux.moon
More file actions
36 lines (28 loc) · 797 Bytes
/
aux.moon
File metadata and controls
36 lines (28 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
math = math
abs = math.abs
DELTA = 1e-10
sign = (x) ->
if x > 0 then return 1
if x == 0 then return 0
return -1
nearest = (x, a, b) ->
if abs(a - x) < abs(b - x) then return a else return b
assertType = (type, value, name) ->
if type(value) ~= type
error name ..' must be a ' .. type .. ' but was ' .. tostring(value) .. '(a ' .. type(value) .. ')'
assertIsPositiveNum = (value, name) ->
if type(value) ~= 'number' or value <= 0
error name .. ' must be a positive integer, but was ' .. tostring(value) .. '(' .. type(value) .. ')'
assertISRect = (x, y, w, h) ->
assertType('number', x, 'x')
assertType('number', y, 'y')
assertIsPositiveNum(w, 'w')
assertIsPositiveNum(h, 'h')
{
:DELTA
:sign
:nearest
:assertType
:assertIsPositiveNum
:assertISRect
}