demos/bp/public/editor-compiled.js
// Draw a path around the specified blob edge. The edge should be a Set3 of (x,y,dir).
Draw a path around the specified blob edge. The edge should be a Set3 of (x,y,dir).
Draw a path around the specified blob edge . The edge should be a Set3 of ( x y dir ) .
function traceEdges(edges, border) {
    const loop = [];
    const visited = new Set3;
    edges.forEach((x, y, dir) => {
      if (visited.has(x, y, dir)) return;
      if (loop.length) {
        loop.push(loop[0], loop[1],
          loop[0], loop[1]);
      }
      const loopStart = loop.length;
      while (!visited.has(x, y, dir)) {
        visited.add(x, y, dir);
        const {dx, dy} = DIRS[dir];
        let x2, y2, dir2;
        if (edges.has(x, y, dir2=(dir+1)%4)) {
          lineTo(loop, x, y, dir, border, -1);
          dir = dir2;
        } else if (edges.has(x2=x-dy, y2=y+dx, dir)) {
          x = x2; y = y2;
        } else if (edges.has(x2=x+dx-dy, y2=y+dy+dx, dir2=(dir+3)%4)) {
          lineTo(loop, x, y, dir, border, 1);
          x = x2; y = y2; dir = dir2;
        } else {
          lineTo(loop, x, y, dir, border, 1);
          lineTo(loop, x-dy, y+dx, (dir+3)%4, border, 1);
          x = x+dx; y = y+dy; dir = (dir+2)%4;
        }
      }
      if (loopStart !== 0) {
        loop.push(loop[loopStart], loop[loopStart+1]);
      }
    });
    return loop.length ? new Float32Array(loop) : null;
  }
function traceEdges ( edges , border ) { const loop = [ ] ; const visited = new Set3 ; edges . forEach ( ( x , y , dir ) => { if ( visited . has ( x , y , dir ) ) return ; if ( loop . length ) { loop . push ( loop [ 0 ] , loop [ 1 ] , loop [ 0 ] , loop [ 1 ] ) ; } const loopStart = loop . length ; while ( ! visited . has ( x , y , dir ) ) { visited . add ( x , y , dir ) ; const { dx , dy } = DIRS [ dir ] ; let x2 , y2 , dir2 ; if ( edges . has ( x , y , dir2 = ( dir + 1 ) % 4 ) ) { lineTo ( loop , x , y , dir , border , - 1 ) ; dir = dir2 ; } else if ( edges . has ( x2 = x - dy , y2 = y + dx , dir ) ) { x = x2 ; y = y2 ; } else if ( edges . has ( x2 = x + dx - dy , y2 = y + dy + dx , dir2 = ( dir + 3 ) % 4 ) ) { lineTo ( loop , x , y , dir , border , 1 ) ; x = x2 ; y = y2 ; dir = dir2 ; } else { lineTo ( loop , x , y , dir , border , 1 ) ; lineTo ( loop , x - dy , y + dx , ( dir + 3 ) % 4 , border , 1 ) ; x = x + dx ; y = y + dy ; dir = ( dir + 2 ) % 4 ; } } if ( loopStart !== 0 ) { loop . push ( loop [ loopStart ] , loop [ loopStart + 1 ] ) ; } } ) ; return loop . length ? new Float32Array ( loop ) : null ; }
Draw a path around the specified blob edge.
Draw a path around the specified blob edge .
// I can't simply draw from the first edge because the shuttle might have // holes (and hence multiple continuous edges). // console.log('v', x, y, dir); // Add degenerate triangles. // console.log('visiting', x, y, dir); // curves down ^| // straight __ // Curves in _| // Loops back on itself immediately. = // console.log('loopy'); // console.log('----- path closed', JSON.stringify(loop), loopStart); // console.log(loop);