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.Vector2 = {};
37Elm.Native.Math.Vector2.make = function(elm) {
39 elm.Native = elm.Native || {};
40 elm.Native.Math = elm.Native.Math || {};
41 elm.Native.Math.Vector2 = elm.Native.Math.Vector2 || {};
42 if (elm.Native.Math.Vector2.values) return elm.Native.Math.Vector2.values;
44 var MJS_FLOAT_ARRAY_TYPE = Float32Array;
48 if (MJS_FLOAT_ARRAY_TYPE == Array) {
49 V2.$ = function V2_$(x, y) {
53 V2.$ = function V2_$(x, y) {
54 return new MJS_FLOAT_ARRAY_TYPE([x, y]);
58 V2.getX = function V2_getX(a) {
61 V2.getY = function V2_getY(a) {
64 V2.setX = function V2_setX(x, a) {
65 return new MJS_FLOAT_ARRAY_TYPE(x, a[1]);
67 V2.setY = function V2_setY(y, a) {
68 return new MJS_FLOAT_ARRAY_TYPE(a[0], y);
71 V2.toTuple = function V2_toTuple(a) {
78 V2.fromTuple = function V2_fromTuple(t) {
79 return new MJS_FLOAT_ARRAY_TYPE([t._0, t._1]);
82 V2.toRecord = function V2_toRecord(a) {
89 V2.fromRecord = function V2_fromRecord(r) {
90 return new MJS_FLOAT_ARRAY_TYPE([r.x, r.y]);
93 V2.add = function V2_add(a, b) {
94 var r = new MJS_FLOAT_ARRAY_TYPE(2);
100 V2.sub = function V2_sub(a, b) {
101 var r = new MJS_FLOAT_ARRAY_TYPE(2);
107 V2.neg = function V2_neg(a) {
108 var r = new MJS_FLOAT_ARRAY_TYPE(2);
114 V2.direction = function V2_direction(a, b) {
115 var r = new MJS_FLOAT_ARRAY_TYPE(2);
118 var im = 1.0 / V2.length(r);
124 V2.length = function V2_length(a) {
125 return Math.sqrt(a[0]*a[0] + a[1]*a[1]);
128 V2.lengthSquared = function V2_lengthSquared(a) {
129 return a[0]*a[0] + a[1]*a[1];
132 V2.distance = function V2_distance(a, b) {
133 var dx = a[0] - b[0];
134 var dy = a[1] - b[1];
135 return Math.sqrt(dx * dx + dy * dy);
138 V2.distanceSquared = function V2_distanceSquared(a) {
139 var dx = a[0] - b[0];
140 var dy = a[1] - b[1];
141 return dx * dx + dy * dy;
144 V2.normalize = function V2_normalize(a) {
145 var r = new MJS_FLOAT_ARRAY_TYPE(2);
146 var im = 1.0 / V2.length(a);
152 V2.scale = function V2_scale(a, k) {
153 var r = new MJS_FLOAT_ARRAY_TYPE(2);
159 V2.dot = function V2_dot(a, b) {
160 return a[0] * b[0] + a[1] * b[1];
170 toRecord: V2.toRecord,
171 fromTuple: V2.fromTuple,
172 fromRecord: V2.fromRecord,
176 direction: F2(V2.direction),
178 lengthSquared: V2.lengthSquared,
179 distance: F2(V2.distance),
180 distanceSquared: F2(V2.distanceSquared),
181 normalize: V2.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