import { IVector4 , IMutableVector , IMutableVector4 } from './IVector' ; import { Array4 , FloatTypedArray , FloatTypedArrayConstructor , } from '../../types/CommonTypes' ; import { Vector4_ } from './Vector4' ; export class MutableVector4_ < T extends FloatTypedArrayConstructor > extends Vector4_ < T > implements IMutableVector , IMutableVector4 { constructor ( x , { type } ) { super ( x , { type } ) ; } set x ( x ) { this . _v [ 0 ] = x ; this . __updateCount ++ ; } get x ( ) : number { return this . _v [ 0 ] ; } set y ( y ) { this . _v [ 1 ] = y ; this . __updateCount ++ ; } get y ( ) : number { return this . _v [ 1 ] ; } set z ( z ) { this . _v [ 2 ] = z ; this . __updateCount ++ ; } get z ( ) : number { return this . _v [ 2 ] ; } set w ( w ) { this . _v [ 3 ] = w ; this . __updateCount ++ ; } get w ( ) : number { return this . _v [ 3 ] ; } raw ( ) { return this . _v ; } setAt ( i , value ) { this . _v [ i ] = value ; this . __updateCount ++ ; return this ; } setComponents ( x , y , z , w ) { this . _v [ 0 ] = x ; this . _v [ 1 ] = y ; this . _v [ 2 ] = z ; this . _v [ 3 ] = w ; this . __updateCount ++ ; return this ; } copyComponents ( vec ) { return this . setComponents ( vec . _v [ 0 ] , vec . _v [ 1 ] , vec . _v [ 2 ] , vec . _v [ 3 ] ) ; } zero ( ) { return this . setComponents ( 0 , 0 , 0 , 0 ) ; } one ( ) { return this . setComponents ( 1 , 1 , 1 , 1 ) ; } /**
     * normalize
     */ normalize ( ) { const length = this . length ( ) ; this . divide ( length ) ; return this ; } normalize3 ( ) { const length = Math . hypot ( this . _v [ 0 ] , this . _v [ 1 ] , this . _v [ 2 ] ) ; this . divide ( length ) ; return this ; } /**
     * add value
     */ add ( vec ) { this . _v [ 0 ] += vec . _v [ 0 ] ; this . _v [ 1 ] += vec . _v [ 1 ] ; this . _v [ 2 ] += vec . _v [ 2 ] ; this . _v [ 3 ] += vec . _v [ 3 ] ; return this ; } /**
     * subtract
     */ subtract ( vec ) { this . _v [ 0 ] -= vec . _v [ 0 ] ; this . _v [ 1 ] -= vec . _v [ 1 ] ; this . _v [ 2 ] -= vec . _v [ 2 ] ; this . _v [ 3 ] -= vec . _v [ 3 ] ; return this ; } /**
     * multiply
     */ multiply ( value ) { this . _v [ 0 ] *= value ; this . _v [ 1 ] *= value ; this . _v [ 2 ] *= value ; this . _v [ 3 ] *= value ; return this ; } /**
     * multiply vector
     */ multiplyVector ( vec ) { this . _v [ 0 ] *= vec . _v [ 0 ] ; this . _v [ 1 ] *= vec . _v [ 1 ] ; this . _v [ 2 ] *= vec . _v [ 2 ] ; this . _v [ 3 ] *= vec . _v [ 3 ] ; return this ; } /**
     * divide
     */ divide ( value ) { if ( value !== 0 ) { this . _v [ 0 ] /= value ; this . _v [ 1 ] /= value ; this . _v [ 2 ] /= value ; this . _v [ 3 ] /= value ; } else { console . error ( '0 division occurred!' ) ; this . _v [ 0 ] = Infinity ; this . _v [ 1 ] = Infinity ; this . _v [ 2 ] = Infinity ; this . _v [ 3 ] = Infinity ; } return this ; } /**
     * divide vector
     */ divideVector ( vec ) { if ( vec . _v [ 0 ] !== 0 && vec . _v [ 1 ] !== 0 && vec . _v [ 2 ] !== 0 && vec . _v [ 3 ] !== 0 ) { this . _v [ 0 ] /= vec . _v [ 0 ] ; this . _v [ 1 ] /= vec . _v [ 1 ] ; this . _v [ 2 ] /= vec . _v [ 2 ] ; this . _v [ 3 ] /= vec . _v [ 3 ] ; } else { console . error ( '0 division occurred!' ) ; this . _v [ 0 ] = vec . _v [ 0 ] === 0 ? Infinity : this . _v [ 0 ] / vec . _v [ 0 ] ; this . _v [ 1 ] = vec . _v [ 1 ] === 0 ? Infinity : this . _v [ 1 ] / vec . _v [ 1 ] ; this . _v [ 2 ] = vec . _v [ 2 ] === 0 ? Infinity : this . _v [ 2 ] / vec . _v [ 2 ] ; this . _v [ 3 ] = vec . _v [ 3 ] === 0 ? Infinity : this . _v [ 3 ] / vec . _v [ 3 ] ; } return this ; } get _updateCount ( ) { return this . __updateCount ; } private __updateCount = 0 ; } export default class MutableVector4 extends MutableVector4_ < Float32ArrayConstructor > { constructor ( x ) { super ( x , { type : Float32Array } ) ; } static fromCopyArray ( array ) { return new MutableVector4 ( new Float32Array ( array ) . slice ( 0 , 4 ) ) ; } static fromCopyArray4 ( array ) { return new MutableVector4 ( new Float32Array ( array ) ) ; } static zero ( ) { return super . _zero ( Float32Array ) as MutableVector4 ; } static one ( ) { return super . _one ( Float32Array ) as MutableVector4 ; } static dummy ( ) { return super . _dummy ( Float32Array ) as MutableVector4 ; } static normalize ( vec ) { return super . _normalize ( vec , Float32Array ) as MutableVector4 ; } static add ( l_vec , r_vec ) { return super . _add ( l_vec , r_vec , Float32Array ) as MutableVector4 ; } static subtract ( l_vec , r_vec ) { return super . _subtract ( l_vec , r_vec , Float32Array ) as MutableVector4 ; } static multiply ( vec , value ) { return super . _multiply ( vec , value , Float32Array ) as MutableVector4 ; } static multiplyVector ( l_vec , r_vec ) { return super . _multiplyVector ( l_vec , r_vec , Float32Array ) as MutableVector4 ; } static divide ( vec , value ) { return super . _divide ( vec , value , Float32Array ) as MutableVector4 ; } static divideVector ( l_vec , r_vec ) { return super . _divideVector ( l_vec , r_vec , Float32Array ) as MutableVector4 ; } get className ( ) { return 'MutableVector4' ; } clone ( ) { return new ( this . constructor as any ) ( new ( this . _v . constructor as any ) ( [ this . _v [ 0 ] , this . _v [ 1 ] , this . _v [ 2 ] , this . _v [ 3 ] , ] ) ) ; } } export class MutableVector4d extends MutableVector4_ < Float64ArrayConstructor > { constructor ( x ) { super ( x , { type : Float64Array } ) ; } static zero ( ) { return super . _zero ( Float64Array ) as MutableVector4d ; } static one ( ) { return super . _one ( Float64Array ) as MutableVector4d ; } static dummy ( ) { return super . _dummy ( Float64Array ) as MutableVector4d ; } static normalize ( vec ) { return super . _normalize ( vec , Float64Array ) as MutableVector4d ; } static add ( l_vec , r_vec ) { return super . _add ( l_vec , r_vec , Float64Array ) as MutableVector4d ; } static subtract ( l_vec , r_vec ) { return super . _subtract ( l_vec , r_vec , Float64Array ) as MutableVector4d ; } static multiply ( vec , value ) { return super . _multiply ( vec , value , Float64Array ) as MutableVector4d ; } static multiplyVector ( l_vec , r_vec ) { return super . _multiplyVector ( l_vec , r_vec , Float64Array ) as MutableVector4d ; } static divide ( vec , value ) { return super . _divide ( vec , value , Float64Array ) as MutableVector4d ; } static divideVector ( l_vec , r_vec ) { return super . _divideVector ( l_vec , r_vec , Float64Array ) as MutableVector4d ; } static fromCopyArray4 ( array ) { return new MutableVector4d ( new Float64Array ( array ) ) ; } static fromCopyArray ( array ) { return new MutableVector4d ( new Float64Array ( array . slice ( 0 , 4 ) ) ) ; } clone ( ) { return super . clone ( ) as MutableVector4d ; } } export type MutableVector4f = MutableVector4 ;