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