@@ 250-260 (lines=11) @@ | ||
247 | var val = this; |
|
248 | return (val < 0); |
|
249 | }, |
|
250 | relativeTo: function(v2, type){ |
|
251 | var v1 = this; |
|
252 | // type .. 0=any, 1=pos, 2=neg |
|
253 | var v = v2 - v1; |
|
254 | if (type == 1) { |
|
255 | return v > 0 ? v : -v; |
|
256 | }else if (type == 2) { |
|
257 | return v > 0 ? -v : v; |
|
258 | } |
|
259 | return v; |
|
260 | }, |
|
261 | round: function(){ |
|
262 | return Math.round(this); |
|
263 | }, |
|
@@ 784-807 (lines=24) @@ | ||
781 | var input = this; |
|
782 | return parseFloat(input.toString().substr(0, digits)); |
|
783 | }, |
|
784 | limit: function(min, max){ |
|
785 | var input = this; |
|
786 | ||
787 | // ensure ok |
|
788 | if (input != input) { /// fast isNaN check |
|
789 | return min; |
|
790 | } |
|
791 | ||
792 | // flip limits if in reverse order |
|
793 | if (min > max) { |
|
794 | var temp = max; |
|
795 | max = min; |
|
796 | min = temp; |
|
797 | } |
|
798 | ||
799 | // ensure within limits |
|
800 | if (input < min) { |
|
801 | return min; |
|
802 | }else if (input > max) { |
|
803 | return max; |
|
804 | } |
|
805 | return input; |
|
806 | }, |
|
807 | limitToArray: function(array, extraMax = 0, extraMin = 0){ |
|
808 | var pointer = this; |
|
809 | if (pointer <= -extraMin) { |
|
810 | return -extraMin; |
|
@@ 830-849 (lines=20) @@ | ||
827 | } |
|
828 | return min + (value % diff); |
|
829 | }, |
|
830 | wrap2: function(min, max){ |
|
831 | var input = this; |
|
832 | ||
833 | // flip limits if in reverse order |
|
834 | if (min > max) { |
|
835 | var temp = max; |
|
836 | max = min; |
|
837 | min = temp; |
|
838 | } |
|
839 | ||
840 | // ensure wrapped to limits |
|
841 | var diff = (max - min) + 1; |
|
842 | while (input < min) { |
|
843 | input += diff; |
|
844 | } |
|
845 | while (input > max) { |
|
846 | input -= diff; |
|
847 | } |
|
848 | return input; |
|
849 | }, |
|
850 | wrapToMax: function(max){ |
|
851 | var value = this; |
|
852 | var diff = max + 1; |