3 * Copyright (c) 2010 Mozilla Corporation
4 * Copyright (c) 2010 Vladimir Vukicevic
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
31 * Vector and Matrix math utilities for JavaScript, optimized for WebGL.
32 * Edited to work with the Elm Programming Language
35Elm.Native.Math = Elm.Native.Math || {};
36Elm.Native.Math.Vector4 = {};
37Elm.Native.Math.Vector4.make = function(elm) {
39 elm.Native = elm.Native || {};
40 elm.Native.Math = elm.Native.Math || {};
41 elm.Native.Math.Vector4 = elm.Native.Math.Vector4 || {};
42 if (elm.Native.Math.Vector4.values) return elm.Native.Math.Vector4.values;
44 var MJS_FLOAT_ARRAY_TYPE = Float32Array;
48 if (MJS_FLOAT_ARRAY_TYPE == Array) {
49 V4.$ = function V4_$(x, y, z, w) {
53 V4.$ = function V4_$(x, y, z, w) {
54 return new MJS_FLOAT_ARRAY_TYPE([x, y, z, w]);
58 V4.getX = function V4_getX(a) {
61 V4.getY = function V4_getY(a) {
64 V4.getZ = function V4_getZ(a) {
67 V4.getW = function V4_getW(a) {
70 V4.setX = function V4_setX(x, a) {
71 return new MJS_FLOAT_ARRAY_TYPE(x, a[1], a[2], a[3]);
73 V4.setY = function V4_setY(y, a) {
74 return new MJS_FLOAT_ARRAY_TYPE(a[0], y, a[2], a[3]);
76 V4.setZ = function V4_setZ(z, a) {
77 return new MJS_FLOAT_ARRAY_TYPE(a[0], a[1], z, a[3]);
79 V4.setW = function V4_setW(w, a) {
80 return new MJS_FLOAT_ARRAY_TYPE(a[0], a[1], a[2], w);
83 V4.toTuple = function V4_toTuple(a) {
92 V4.fromTuple = function V4_fromTuple(t) {
93 return new MJS_FLOAT_ARRAY_TYPE([t._0, t._1, t._2, t._3]);
96 V4.toRecord = function V4_toRecord(a) {
105 V4.fromRecord = function V4_fromRecord(r) {
106 return new MJS_FLOAT_ARRAY_TYPE([r.x, r.y, r.z, r.w]);
109 V4.add = function V4_add(a, b) {
110 var r = new MJS_FLOAT_ARRAY_TYPE(4);
118 V4.sub = function V4_sub(a, b) {
119 var r = new MJS_FLOAT_ARRAY_TYPE(4);
127 V4.neg = function V4_neg(a) {
128 var r = new MJS_FLOAT_ARRAY_TYPE(4);
136 V4.direction = function V4_direction(a, b) {
137 var r = new MJS_FLOAT_ARRAY_TYPE(4);
142 var im = 1.0 / V4.length(r);
150 V4.length = function V4_length(a) {
151 return Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2] + a[3]*a[3]);
154 V4.lengthSquared = function V4_lengthSquared(a) {
155 return a[0]*a[0] + a[1]*a[1] + a[2]*a[2] + a[3]*a[3];
158 V4.distance = function V4_distance(a, b) {
159 var dx = a[0] - b[0];
160 var dy = a[1] - b[1];
161 var dz = a[2] - b[2];
162 var dw = a[3] - b[3];
163 return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
166 V4.distanceSquared = function V4_distanceSquared(a) {
167 var dx = a[0] - b[0];
168 var dy = a[1] - b[1];
169 var dz = a[2] - b[2];
170 var dw = a[3] - b[3];
171 return dx * dx + dy * dy + dz * dz + dw * dw;
174 V4.normalize = function V4_normalize(a) {
175 var r = new MJS_FLOAT_ARRAY_TYPE(4);
176 var im = 1.0 / V4.length(a);
184 V4.scale = function V4_scale(a, k) {
185 var r = new MJS_FLOAT_ARRAY_TYPE(4);
193 V4.dot = function V4_dot(a, b) {
194 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
208 toRecord: V4.toRecord,
209 fromTuple: V4.fromTuple,
210 fromRecord: V4.fromRecord,
214 direction: F2(V4.direction),
216 lengthSquared: V4.lengthSquared,
217 distance: F2(V4.distance),
218 distanceSquared: F2(V4.distanceSquared),
219 normalize: V4.normalize,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list