examples/lib/d3.layout.cloud.js
function cloudCollide(tag, board, sw) {
    sw >>= 5;
    var sprite = tag.sprite,
        w = tag.width >> 5,
        lx = tag.x - (w << 4),
        sx = lx & 0x7f,
        msx = 32 - sx,
        h = tag.y1 - tag.y0,
        x = (tag.y + tag.y0) * sw + (lx >> 5),
        last;
    for (var j = 0; j < h; j++) {
      last = 0;
      for (var i = 0; i <= w; i++) {
        if (((last << msx) | (i < w ? (last = sprite[j * w + i]) >>> sx : 0))
            & board[x + i]) return true;
      }
      x += sw;
    }
    return false;
  }
function cloudCollide(tag, board, sw) {
    sw >>= 5;
    var sprite = tag.sprite,
        w = tag.width >> 5,
        lx = tag.x - (w << 4),
        sx = lx & 0x7f,
        msx = 32 - sx,
        h = tag.y1 - tag.y0,
        x = (tag.y + tag.y0) * sw + (lx >> 5),
        last;
    for (var j = 0; j < h; j++) {
      last = 0;
      for (var i = 0; i <= w; i++) {
        if (((last << msx) | (i < w ? (last = sprite[j * w + i]) >>> sx : 0))
            & board[x + i]) return true;
      }
      x += sw;
    }
    return false;
  }
function cloudCollide ( tag , board , sw ) { sw >>= 5 ; var sprite = tag . sprite , w = tag . width >> 5 , lx = tag . x - ( w << 4 ) , sx = lx & 0x7f , msx = 32 - sx , h = tag . y1 - tag . y0 , x = ( tag . y + tag . y0 ) * sw + ( lx >> 5 ) , last ; for ( var j = 0 ; j < h ; j ++ ) { last = 0 ; for ( var i = 0 ; i <= w ; i ++ ) { if ( ( ( last << msx ) | ( i < w ? ( last = sprite [ j * w + i ] ) >>> sx : 0 ) ) & board [ x + i ] ) return true ; } x += sw ; } return false ; }
Use mask-based collision detection.
Use mask - based collision detection .