import { MiTools , Tools } from '@components/canvas/Tools' ; import { Canvas } from '@components/canvas/Canvas' ; import { Point } from '@components/canvas/Point' ; export class Laser extends Tools implements MiTools { name = 'laser' ; start = new Point ( 0 , 0 ) ; end = new Point ( 0 , 0 ) ; protected cursor : any ; protected laser : any ; param canvas constructor ( canvas ) { super ( canvas ) ; Tools . instances [ this . name ] = this ; } param ctx param start param end draw ( ctx ? , start ? , end ? ) { ctx = ctx ?? this . getBufferContext ( ) ; start = start ?? this . start ; end = end ?? this . end ; ctx . beginPath ( ) ; ctx . moveTo ( start . x , start . y ) ; ctx . lineTo ( end . x , end . y ) ; ctx . closePath ( ) ; ctx . stroke ( ) ; } param event protected drawBegin ( event ) { this . start = this . createPoint ( event . clientX , event . clientY ) ; this . buffer = this . createBuffer ( ) ; this . drawUpdate ( event ) ; } param event protected drawUpdate ( event ) { const point = this . createPoint ( event . clientX , event . clientY ) , distance = point . distance ( this . start ) ; if ( distance >= Tools . distance ) { this . end = point ; this . draw ( ) ; } } param event protected drawEnd ( event ) { this . resetBuffer ( ) ; } }