import { Point } from '@components/canvas/Point' ; const RectWorker = self as any ; RectWorker . onmessage = ( data ) => { const points = data . data as Point [ ] ; let minx ! , miny ! , maxx ! , maxy ! ; for ( let i = 0 , len = points . length ; i < len ; i ++ ) { const point = points [ i ] ; if ( i === 0 ) { minx = point . x ; miny = point . y ; maxx = point . x ; maxy = point . y ; } else { if ( point . x < minx ) minx = point . x ; if ( point . y < miny ) miny = point . y ; if ( point . x > maxx ) maxx = point . x ; if ( point . y > maxy ) maxy = point . y ; } } const x = Math . floor ( minx ) - 10 , y = Math . floor ( miny ) - 10 , width = Math . ceil ( maxx - minx ) + 20 , height = Math . ceil ( maxy - miny ) + 20 ; RectWorker . postMessage ( { x , y , width , height } ) ; self . close ( ) ; } ;