fiirst
This commit is contained in:
parent
4f5cf7d425
commit
2d42f7f487
7 changed files with 4065 additions and 0 deletions
24
js/vector.js
Normal file
24
js/vector.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
const root = window.PixelIslandModules ||= {};
|
||||
|
||||
root.Vec2 = {
|
||||
add(a, b) {
|
||||
return { x: a.x + b.x, y: a.y + b.y };
|
||||
},
|
||||
sub(a, b) {
|
||||
return { x: a.x - b.x, y: a.y - b.y };
|
||||
},
|
||||
scale(v, amount) {
|
||||
return { x: v.x * amount, y: v.y * amount };
|
||||
},
|
||||
length(v) {
|
||||
return Math.hypot(v.x, v.y);
|
||||
},
|
||||
normalize(v) {
|
||||
const length = Math.hypot(v.x, v.y) || 1;
|
||||
return { x: v.x / length, y: v.y / length };
|
||||
}
|
||||
};
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue