modules/polygon/src/lineclip.js
// intersect a segment against one of the 4 lines that make up the bbox
intersect a segment against one of the 4 lines that make up the bbox
intersect a segment against one of the 4 lines that make up the bbox
function intersect(a, b, edge, bbox, out = []) {
  let t;
  let snap;
  if (edge & 8) {
    t = (bbox[3] - a[1]) / (b[1] - a[1]);
    snap = 3;
  } else if (edge & 4) {
    t = (bbox[1] - a[1]) / (b[1] - a[1]);
    snap = 1;
  } else if (edge & 2) {
    t = (bbox[2] - a[0]) / (b[0] - a[0]);
    snap = 2;
  } else if (edge & 1) {
    t = (bbox[0] - a[0]) / (b[0] - a[0]);
    snap = 0;
  } else {
    return null;
  }
  for (let i = 0; i < a.length; i++) {
    out[i] = (snap & 1) === i ? bbox[snap] : t * (b[i] - a[i]) + a[i];
  }
  return out;
}
function intersect ( a , b , edge , bbox , out = [ ] ) { let t ; let snap ; if ( edge & 8 ) { t = ( bbox [ 3 ] - a [ 1 ] ) / ( b [ 1 ] - a [ 1 ] ) ; snap = 3 ; } else if ( edge & 4 ) { t = ( bbox [ 1 ] - a [ 1 ] ) / ( b [ 1 ] - a [ 1 ] ) ; snap = 1 ; } else if ( edge & 2 ) { t = ( bbox [ 2 ] - a [ 0 ] ) / ( b [ 0 ] - a [ 0 ] ) ; snap = 2 ; } else if ( edge & 1 ) { t = ( bbox [ 0 ] - a [ 0 ] ) / ( b [ 0 ] - a [ 0 ] ) ; snap = 0 ; } else { return null ; } for ( let i = 0 ; i < a . length ; i ++ ) { out [ i ] = ( snap & 1 ) === i ? bbox [ snap ] : t * ( b [ i ] - a [ i ] ) + a [ i ] ; } return out ; }
intersect a segment against one of the 4 lines that make up the bbox
intersect a segment against one of the 4 lines that make up the bbox
// Forces out[snapI] to be on the bbox edge // Interpolation introduces precision issue which may cause lineclip to be // stuck in an infinite loop // top // bottom // right // left