diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/vec2.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/vec2.js | 432 |
1 files changed, 216 insertions, 216 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/math/vec2.js b/js/helper-classes/RDGE/src/core/script/math/vec2.js index 0a5b832d..c62e57ab 100755 --- a/js/helper-classes/RDGE/src/core/script/math/vec2.js +++ b/js/helper-classes/RDGE/src/core/script/math/vec2.js | |||
@@ -1,216 +1,216 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, are permitted provided that the following conditions are met: |
8 | 8 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 9 | - Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 10 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | - Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the | 12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. | 13 | documentation and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | - Neither the name of Motorola Mobility nor the names of its contributors |
15 | may be used to endorse or promote products derived from this software | 15 | may be used to endorse or promote products derived from this software |
16 | without specific prior written permission. | 16 | without specific prior written permission. |
17 | 17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * RDGE.vec2 = {} | 33 | * RDGE.vec2 = {} |
34 | * This library contains functions for operating on 2D vectors. | 34 | * This library contains functions for operating on 2D vectors. |
35 | * A 2D vector can be any array containing at least 2 numeric components. | 35 | * A 2D vector can be any array containing at least 2 numeric components. |
36 | * All of the following are valid methods for declaring a RDGE.vec2: | 36 | * All of the following are valid methods for declaring a RDGE.vec2: |
37 | * var a = [0, 1]; | 37 | * var a = [0, 1]; |
38 | * var b = RDGE.vec2.zero(); | 38 | * var b = RDGE.vec2.zero(); |
39 | * var c = RDGE.vec2.up(); | 39 | * var c = RDGE.vec2.up(); |
40 | */ | 40 | */ |
41 | var RDGE = RDGE || {}; | 41 | var RDGE = RDGE || {}; |
42 | RDGE.vec2 = {}; | 42 | RDGE.vec2 = {}; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * RDGE.vec2.string | 45 | * RDGE.vec2.string |
46 | */ | 46 | */ |
47 | RDGE.vec2.string = function (v) { | 47 | RDGE.vec2.string = function (v) { |
48 | return "{ " + v[0] + ", " + v[1] + " }"; | 48 | return "{ " + v[0] + ", " + v[1] + " }"; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * RDGE.vec2.verify | 52 | * RDGE.vec2.verify |
53 | * This function is provided for debugging purposes only. It is not recommended | 53 | * This function is provided for debugging purposes only. It is not recommended |
54 | * to be used in performance critical areas of the code. | 54 | * to be used in performance critical areas of the code. |
55 | */ | 55 | */ |
56 | RDGE.vec2.verify = function (v) { | 56 | RDGE.vec2.verify = function (v) { |
57 | if (v == undefined || v.length == undefined || v.length < 2) { | 57 | if (v == undefined || v.length == undefined || v.length < 2) { |
58 | return false; | 58 | return false; |
59 | } | 59 | } |
60 | 60 | ||
61 | if (typeof (v[0]) != "number" || typeof (v[1]) != "number") { | 61 | if (typeof (v[0]) != "number" || typeof (v[1]) != "number") { |
62 | return false; | 62 | return false; |
63 | } | 63 | } |
64 | 64 | ||
65 | return true; | 65 | return true; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * RDGE.vec2.copy | 69 | * RDGE.vec2.copy |
70 | */ | 70 | */ |
71 | RDGE.vec2.copy = function (v) { | 71 | RDGE.vec2.copy = function (v) { |
72 | if (v.length == undefined) { | 72 | if (v.length == undefined) { |
73 | return [v, v]; | 73 | return [v, v]; |
74 | } | 74 | } |
75 | 75 | ||
76 | return [v[0], v[1]]; | 76 | return [v[0], v[1]]; |
77 | }; | 77 | }; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * RDGE.vec2.inplace_copy | 80 | * RDGE.vec2.inplace_copy |
81 | */ | 81 | */ |
82 | RDGE.vec2.inplace_copy = function (dst, src) { | 82 | RDGE.vec2.inplace_copy = function (dst, src) { |
83 | dst[0] = src[0]; | 83 | dst[0] = src[0]; |
84 | dst[1] = src[1]; | 84 | dst[1] = src[1]; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * RDGE.vec2.zero | 88 | * RDGE.vec2.zero |
89 | */ | 89 | */ |
90 | RDGE.vec2.zero = function () { | 90 | RDGE.vec2.zero = function () { |
91 | return [0.0, 0.0]; | 91 | return [0.0, 0.0]; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * RDGE.vec2.up | 95 | * RDGE.vec2.up |
96 | */ | 96 | */ |
97 | RDGE.vec2.up = function () { | 97 | RDGE.vec2.up = function () { |
98 | return [0.0, 1.0]; | 98 | return [0.0, 1.0]; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * RDGE.vec2.right | 102 | * RDGE.vec2.right |
103 | */ | 103 | */ |
104 | RDGE.vec2.right = function () { | 104 | RDGE.vec2.right = function () { |
105 | return [1.0, 0.0]; | 105 | return [1.0, 0.0]; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * RDGE.vec2.add | 109 | * RDGE.vec2.add |
110 | */ | 110 | */ |
111 | RDGE.vec2.add = function (a, b) { | 111 | RDGE.vec2.add = function (a, b) { |
112 | return [a[0] + b[0], a[1] + b[1]]; | 112 | return [a[0] + b[0], a[1] + b[1]]; |
113 | }; | 113 | }; |
114 | /** | 114 | /** |
115 | * RDGE.vec2.sub | 115 | * RDGE.vec2.sub |
116 | */ | 116 | */ |
117 | RDGE.vec2.sub = function (a, b) { | 117 | RDGE.vec2.sub = function (a, b) { |
118 | return [a[0] - b[0], a[1] - b[1]]; | 118 | return [a[0] - b[0], a[1] - b[1]]; |
119 | }; | 119 | }; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * RDGE.vec2.mul | 122 | * RDGE.vec2.mul |
123 | */ | 123 | */ |
124 | RDGE.vec2.mul = function (a, b) { | 124 | RDGE.vec2.mul = function (a, b) { |
125 | return [a[0] * b[0], a[1] * b[1]]; | 125 | return [a[0] * b[0], a[1] * b[1]]; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * RDGE.vec2.addMul | 129 | * RDGE.vec2.addMul |
130 | */ | 130 | */ |
131 | RDGE.vec2.addMul = function (a, b, s) { | 131 | RDGE.vec2.addMul = function (a, b, s) { |
132 | if (s.length != undefined && s.length >= 2) { |