UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 3.01 kB
var t;class h{constructor(t=0,h=0,s=0,i=0){this.x=void 0,this.y=void 0,this.z=void 0,this.w=void 0,4===t.length?(this.x=t[0],this.y=t[1],this.z=t[2],this.w=t[3]):(this.x=t,this.y=h,this.z=s,this.w=i)}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}add2(t,h){return this.x=t.x+h.x,this.y=t.y+h.y,this.z=t.z+h.z,this.w=t.w+h.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addScaled(t,h){return this.x+=t.x*h,this.y+=t.y*h,this.z+=t.z*h,this.w+=t.w*h,this}clone(){return new(0,this.constructor)(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}div(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}div2(t,h){return this.x=t.x/h.x,this.y=t.y/h.y,this.z=t.z/h.z,this.w=t.w/h.w,this}divScalar(t){return this.x/=t,this.y/=t,this.z/=t,this.w/=t,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w}equalsApprox(t,h=1e-6){return Math.abs(this.x-t.x)<h&&Math.abs(this.y-t.y)<h&&Math.abs(this.z-t.z)<h&&Math.abs(this.w-t.w)<h}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}lerp(t,h,s){return this.x=t.x+s*(h.x-t.x),this.y=t.y+s*(h.y-t.y),this.z=t.z+s*(h.z-t.z),this.w=t.w+s*(h.w-t.w),this}mul(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}mul2(t,h){return this.x=t.x*h.x,this.y=t.y*h.y,this.z=t.z*h.z,this.w=t.w*h.w,this}mulScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}normalize(t=this){const h=t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w;if(h>0){const s=1/Math.sqrt(h);this.x=t.x*s,this.y=t.y*s,this.z=t.z*s,this.w=t.w*s}return this}floor(t=this){return this.x=Math.floor(t.x),this.y=Math.floor(t.y),this.z=Math.floor(t.z),this.w=Math.floor(t.w),this}ceil(t=this){return this.x=Math.ceil(t.x),this.y=Math.ceil(t.y),this.z=Math.ceil(t.z),this.w=Math.ceil(t.w),this}round(t=this){return this.x=Math.round(t.x),this.y=Math.round(t.y),this.z=Math.round(t.z),this.w=Math.round(t.w),this}min(t){return t.x<this.x&&(this.x=t.x),t.y<this.y&&(this.y=t.y),t.z<this.z&&(this.z=t.z),t.w<this.w&&(this.w=t.w),this}max(t){return t.x>this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),t.w>this.w&&(this.w=t.w),this}set(t,h,s,i){return this.x=t,this.y=h,this.z=s,this.w=i,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}sub2(t,h){return this.x=t.x-h.x,this.y=t.y-h.y,this.z=t.z-h.z,this.w=t.w-h.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}fromArray(t,h=0){var s,i,r,w;return this.x=null!=(s=t[h])?s:this.x,this.y=null!=(i=t[h+1])?i:this.y,this.z=null!=(r=t[h+2])?r:this.z,this.w=null!=(w=t[h+3])?w:this.w,this}toString(){return`[${this.x}, ${this.y}, ${this.z}, ${this.w}]`}toArray(t=[],h=0){return t[h]=this.x,t[h+1]=this.y,t[h+2]=this.z,t[h+3]=this.w,t}}t=h,h.ZERO=Object.freeze(new t(0,0,0,0)),h.ONE=Object.freeze(new t(1,1,1,1));export{h as Vec4};