import { SGItem } from '../scenegraph' ; param item export function getItemSpace ( item ) { const { x , xc , x2 , y , yc , y2 , width , height } = item ; const computeDimension = ( low , high , center , span ) => { let origin ; let resultSpan ; if ( low !== undefined ) { if ( high !== undefined ) { origin = Math . min ( low , high ) ; resultSpan = Math . abs ( high - low ) ; } else if ( span !== undefined ) { origin = low ; resultSpan = span ; } else if ( center !== undefined ) { origin = Math . min ( low , center ) ; resultSpan = Math . abs ( center - low ) * 2 ; } else { origin = low ; } } else if ( high !== undefined ) { if ( span !== undefined ) { origin = high - span ; resultSpan = span ; } else if ( center !== undefined ) { resultSpan = Math . abs ( high - center ) * 2 ; origin = center < high ? high - ( high - center ) * 2 : center - ( center - high ) ; } } else if ( span !== undefined && center !== undefined ) { origin = center - span / 2 ; resultSpan = span ; } return [ origin , resultSpan ] ; } ; const [ originX , resultWidth ] = computeDimension ( x , x2 , xc , width ) ; const [ originY , resultHeight ] = computeDimension ( y , y2 , yc , height ) ; return { origin : { x : originX || 0 , y : originY || 0 , } , shape : { width : resultWidth , height : resultHeight , } , } ; } export interface ItemSpace { origin : { x : number ; y : number ; } ; shape : { width : number | undefined ; height : number | undefined ; } ; }