-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector.min.js
1 lines (1 loc) · 4.41 KB
/
Vector.min.js
1
class Vector{constructor(e,f){e==void 0&&f==void 0?(this.x=0,this.y=0):this.set(e,f)}set(e,f){f==void 0?e.x==void 0?(this.x=e,this.y=e):(this.x=e.x,this.y=e.y):(this.x=e,this.y=f)}getCopy(){return new Vector(this.x,this.y)}getEquals(e,f){return void 0==f?this.x==e.x&&this.y==e.y:this.x==e&&this.y==f}add(e,f){f==void 0?e.x==void 0?(this.x+=e,this.y+=e):(this.x+=e.x,this.y+=e.y):(this.x+=e,this.y+=f)}getAdded(e,f){return void 0==f?void 0==e.x?new Vector(this.x+e,this.y+e):new Vector(this.x+e.x,this.y+e.y):new Vector(this.x+e,this.y+f)}subtract(e,f){f==void 0?e.x==void 0?(this.x-=e,this.y-=e):(this.x-=e.x,this.y-=e.y):(this.x-=e,this.y-=f)}getSubtracted(e,f){return void 0==f?void 0==e.x?new Vector(this.x-e,this.y-e):new Vector(this.x-e.x,this.y-e.y):new Vector(this.x-e,this.y-f)}divide(e,f){f==void 0?e.x==void 0?(this.x/=e,this.y/=e):(this.x/=e.x,this.y/=e.y):(this.x/=e,this.y/=f)}getDivided(e,f){return void 0==f?void 0==e.x?new Vector(this.x/e,this.y/e):new Vector(this.x/e.x,this.y/e.y):new Vector(this.x/e,this.y/f)}multiply(e,f){f==void 0?e.x==void 0?(this.x*=e,this.y*=e):(this.x*=e.x,this.y*=e.y):(this.x*=e,this.y*=f)}getMultiplied(e,f){return void 0==f?void 0==e.x?new Vector(this.x*e,this.y*e):new Vector(this.x*e.x,this.y*e.y):new Vector(this.x*e,this.y*f)}getDistanceSquared(e,f){return void 0==f?(this.x-e.x)*(this.x-e.x)+(this.y-e.y)*(this.y-e.y):(this.x-e)*(this.x-e)+(this.y-f)*(this.y-f)}static getDistanceSquared(e,f,g,h){if(4==arguments.length)return(e-g)*(e-g)+(f-h)*(f-h);if(3==arguments.length){if("object"==typeof e&&"number"==typeof f&&"number"==typeof g)return(e.x-f)*(e.x-f)+(e.y-g)*(e.y-g);if("number"==typeof e&&"number"==typeof f&&"object"==typeof g)return(e-g.x)*(e-g.x)+(f-g.y)*(f-g.y)}else return(e.x-f.x)*(e.x-f.x)+(e.y-f.y)*(e.y-f.y)}getDistance(e,f){return void 0==f?Math.sqrt((this.x-e.x)*(this.x-e.x)+(this.y-e.y)*(this.y-e.y)):Math.sqrt((this.x-e)*(this.x-e)+(this.y-f)*(this.y-f))}static getDistance(e,f,g,h){if(4==arguments.length)return Math.sqrt((e-g)*(e-g)+(f-h)*(f-h));if(3==arguments.length){if("object"==typeof e&&"number"==typeof f&&"number"==typeof g)return Math.sqrt((e.x-f)*(e.x-f)+(e.y-g)*(e.y-g));if("number"==typeof e&&"number"==typeof f&&"object"==typeof g)return Math.sqrt((e-g.x)*(e-g.x)+(f-g.y)*(f-g.y))}else return Math.sqrt((e.x-f.x)*(e.x-f.x)+(e.y-f.y)*(e.y-f.y))}getLengthSquared(){return this.x*this.x+this.y*this.y}getLength(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){this.divide(this.getLength())}getNormalized(){return this.getDivided(this.getLength())}getNormal(e){return e?new Vector(-this.y,this.x):new Vector(this.y,-this.x)}rotate(e,f,g){f==void 0?this.set(this.x*Math.cos(e)-this.y*Math.sin(e),this.x*Math.sin(e)+this.y*Math.cos(e)):g==void 0?this.set((this.x-f.x)*Math.cos(e)-(this.y-f.y)*Math.sin(e)+f.x,(this.y-f.y)*Math.cos(e)+(this.x-f.x)*Math.sin(e)+f.y):this.set((this.x-f)*Math.cos(e)-(this.y-f)*Math.sin(e)+f,(this.y-g)*Math.cos(e)+(this.x-g)*Math.sin(e)+g)}getRotated(e,f,g){return void 0==f?new Vector(this.x*Math.cos(e)-this.y*Math.sin(e),this.x*Math.sin(e)+this.y*Math.cos(e)):void 0==g?new Vector((this.x-f.x)*Math.cos(e)-(this.y-f.y)*Math.sin(e)+f.x,(this.y-f.y)*Math.cos(e)+(this.x-f.x)*Math.sin(e)+f.y):new Vector((this.x-f)*Math.cos(e)-(this.y-f)*Math.sin(e)+f,(this.y-g)*Math.cos(e)+(this.x-g)*Math.sin(e)+g)}setRotation(e,f,g){var h;h=void 0==f?Math.atan2(this.y,this.x):void 0==g?Math.atan2(this.y-f.y,this.x-f.x):Math.atan2(this.y-g,this.x-f),this.rotate(e-h,f,g)}getWithRotation(e,f,g){var h;return h=void 0==f?Math.atan2(this.y,this.x):void 0==g?Math.atan2(this.y-f.y,this.x-f.x):Math.atan2(this.y-g,this.x-f),this.getRotated(e-h,f,g)}getRotation(e,f){return void 0==e?Math.atan2(this.y,this.x):void 0==f?Math.atan2(this.y-e.y,this.x-e.x):Math.atan2(this.y-f,this.x-e)}getDotProduct(e,f){return void 0==f?this.x*e.x+this.y*e.y:this.x*e+this.y*f}static getDotProduct(e,f,g,h){if(4==arguments.length)return e*g+f*h;if(3==arguments.length){if("object"==typeof e&&"number"==typeof f&&"number"==typeof g)return e.x*f+e.y*g;if("number"==typeof e&&"number"==typeof f&&"object"==typeof g)return e*g.x+f*g.y}else return e.x*f.x+e.y*f.y}getCrossProduct(e,f){return void 0==f?this.x*e.y-e.x*this.y:this.x*f-e*this.y}static getCrossProduct(e,f,g,h){if(4==arguments.length)return e*h-f*g;if(3==arguments.length){if("object"==typeof e&&"number"==typeof f&&"number"==typeof g)return e.x*g-e.y*f;if("number"==typeof e&&"number"==typeof f&&"object"==typeof g)return e*g.y-f*g.x}else return e.x*f.y-e.y*f.x}}