-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector-min.js
1 lines (1 loc) · 1.17 KB
/
vector-min.js
1
Vector=function(){function e(e,t){this.x=e;this.y=t}function t(){var e;if(!this.is_zero()){e=this.length;this.x/=e;this.y/=e}return this}function n(e){this.x+=e.x;this.y+=e.y;return this}function r(e){this.x-=e.x;this.y-=e.y;return this}function i(e){this.x*=e;this.y*=e;return this}function s(){return new e(this.y,this.x*-1)}function o(){return new e(this.y*-1,this.x)}function u(e){return this.x*e.x+this.y*e.y}function a(e){return this.x*e.y-this.y*e.x}function f(e){return this.cross_product(e)===0}function l(e){return this.dot_product(e)===0}function c(){return this.x===0&&this.y===0}function h(){return new e(this.x,this.y)}function p(e){var t=e.clone().normalize(),n=this.dot_product(e);return t.multiply_by_scalar(n)}function d(){return[this.x,this.y]}function v(){return this.x+","+this.y}e.prototype={get length(){return Math.sqrt(this.x*this.x+this.y*this.y)},set length(e){this.normalize().multiply_by_scalar(e)},x:0,y:0,is_zero:c,normalize:t,add:n,subtract:r,multiply_by_scalar:i,left_normal:s,right_normal:o,dot_product:u,cross_product:a,clone:h,is_parallel_to:f,is_perpendicular_to:l,projected_onto:p,to_array:d,to_string:v};e.x_axis=new e(1,0);e.y_axis=new e(0,1);return e}();