import { IMatrixFunc } from '../../typings' ; import { DEFAULT_ACCURATE_DIGIT , DEFAULT_MATRIX_DIGIT , DEFAULT_SIZE_DIGIT } from '../const' ; import { combineMatrix } from './combine' ; import { shorten } from './shorten' ; export const merge = ( func1 , func2 , digit1 = DEFAULT_MATRIX_DIGIT , digit2 = DEFAULT_SIZE_DIGIT , digit3 = DEFAULT_ACCURATE_DIGIT ) : IMatrixFunc => { let resFunc = { type : func1 . type , val : [ ] , } ; switch ( func1 . type ) { case 'translate' : if ( func1 . val . length === 1 ) { func1 . val [ 1 ] = 0 ; } if ( func2 . val . length === 1 ) { func2 . val [ 1 ] = 0 ; } resFunc . val = [ func1 . val [ 0 ] + func2 . val [ 0 ] , func1 . val [ 1 ] + func2 . val [ 1 ] ] ; break ; case 'scale' : if ( func1 . val . length === 1 ) { func1 . val [ 1 ] = func1 . val [ 0 ] ; } if ( func2 . val . length === 1 ) { func2 . val [ 1 ] = func2 . val [ 0 ] ; } resFunc . val = [ func1 . val [ 0 ] * func2 . val [ 0 ] , func1 . val [ 1 ] * func2 . val [ 1 ] ] ; break ; case 'rotate' : if ( func1 . val . length === 1 && func2 . val . length === 1 ) { resFunc . val [ 0 ] = func1 . val [ 0 ] + func2 . val [ 0 ] ; } else if ( func1 . val [ 1 ] === func2 . val [ 1 ] && func1 . val [ 2 ] === func2 . val [ 2 ] ) { resFunc . val = [ func1 . val [ 0 ] + func2 . val [ 0 ] , func1 . val [ 1 ] , func1 . val [ 2 ] ] ; } else { resFunc = combineMatrix ( [ func1 , func2 ] , digit1 , digit2 , digit3 ) ; } break ; case 'skewX' : case 'skewY' : resFunc = combineMatrix ( [ func1 , func2 ] , digit1 , digit2 , digit3 ) ; break ; default : return combineMatrix ( [ func1 , func2 ] , digit1 , digit2 , digit3 ) ; } return shorten ( resFunc , digit1 , digit2 , digit3 ) ; } ;