@@ 690-712 (lines=23) @@ | ||
687 | limitToDigits: function(input, digits){ |
|
688 | return parseFloat(input.toString().substr(0, digits)); |
|
689 | }, |
|
690 | limit: function(input, min, max){ |
|
691 | ||
692 | // ensure ok |
|
693 | if (input != input) { /// fast isNaN check |
|
694 | return min; |
|
695 | } |
|
696 | ||
697 | // flip limits if in reverse order |
|
698 | if (min > max) { |
|
699 | var temp = max; |
|
700 | max = min; |
|
701 | min = temp; |
|
702 | } |
|
703 | ||
704 | // ensure within limits |
|
705 | if (input < min) { |
|
706 | return min; |
|
707 | } |
|
708 | if (input > max) { |
|
709 | return max; |
|
710 | } |
|
711 | return input; |
|
712 | }, |
|
713 | limitToArray: function(pointer, array, extraMax = 0, extraMin = 0){ |
|
714 | if (pointer <= -extraMin) { |
|
715 | return -extraMin; |
|
@@ 735-753 (lines=19) @@ | ||
732 | } |
|
733 | return min + (value % diff); |
|
734 | }, |
|
735 | wrap2: function(input, min, max){ |
|
736 | ||
737 | // flip limits if in reverse order |
|
738 | if (min > max) { |
|
739 | var temp = max; |
|
740 | max = min; |
|
741 | min = temp; |
|
742 | } |
|
743 | ||
744 | // ensure wrapped to limits |
|
745 | var diff = (max - min) + 1; |
|
746 | while (input < min) { |
|
747 | input += diff; |
|
748 | } |
|
749 | while (input > max) { |
|
750 | input -= diff; |
|
751 | } |
|
752 | return input; |
|
753 | }, |
|
754 | wrapToMax: function(value, max){ |
|
755 | var diff = max + 1; |
|
756 | while (value < 0) { |
|
@@ 173-182 (lines=10) @@ | ||
170 | isNegative: function(val){ |
|
171 | return (val < 0); |
|
172 | }, |
|
173 | relativeTo: function(v1, v2, type){ |
|
174 | // type .. 0=any, 1=pos, 2=neg |
|
175 | var v = v2 - v1; |
|
176 | if (type == 1) { |
|
177 | return v > 0 ? v : -v; |
|
178 | }else if (type == 2) { |
|
179 | return v > 0 ? -v : v; |
|
180 | } |
|
181 | return v; |
|
182 | }, |
|
183 | abs: function(v, negative = false){ |
|
184 | if (negative){ |
|
185 | return v > 0 ? -v : v; |