/**
 * This helper returns true is the pixel at (x,y) in the given WebGL context is
 * colored, and false else.
 */ export function isPixelColored ( gl , x , y ) { const pixels = new Uint8Array ( 4 ) ; gl . readPixels ( x , gl . drawingBufferHeight - y , 1 , 1 , gl . RGBA , gl . UNSIGNED_BYTE , pixels ) ; return pixels [ 3 ] > 0 ; } /**
 * This helper checks whether or not a point (x, y) collides with an
 * edge, connecting a source (xS, yS) to a target (xT, yT) with a thickness in
 * pixels.
 */ export function doEdgeCollideWithPoint ( x , y , xS , yS , xT , yT , thickness ) { if ( x < xS - thickness && x < xT - thickness ) return false ; if ( y < yS - thickness && y < yT - thickness ) return false ; if ( x > xS + thickness && x > xT + thickness ) return false ; if ( y > yS + thickness && y > yT + thickness ) return false ; const distance = Math . abs ( ( xT - xS ) * ( yS - y ) - ( xS - x ) * ( yT - yS ) ) / Math . sqrt ( Math . pow ( xT - xS , 2 ) + Math . pow ( yT - yS , 2 ) ) ; return distance < thickness / 2 ; }