example/bundle.js
// combine compatible tunnels (same direction, tunnelWidth, and position)
combine compatible tunnels (same direction, tunnelWidth, and position)
combine compatible tunnels ( same direction tunnelWidth and position )
_mergeTunnels() {
    const deleted = {}
    for (let obj of Array.from(this.objects)) {
      for (let obj2 of Array.from(this.objects)) {
        if (!(deleted[obj2.id] || deleted[obj.id])) {
          if (obj.id > obj2.id) {
            if ((obj.type === 'tunnel') && (obj2.type === 'tunnel')) {
              var max, min, width
              if (((obj.direction === 'EAST') || (obj.direction === 'WEST')) && ((obj2.direction === 'EAST') || (obj2.direction === 'WEST'))) {
                if ((obj.y === obj2.y) && (obj.height === obj2.height)) {
                  if (intersect1D(obj.x, obj.x + obj.width, obj2.x, obj2.x + obj2.width)) {
                    min = Math.min(obj.x, obj2.x)
                    max = Math.max(obj.x + obj.width, obj2.x + obj2.width)
                    width = (max - min) + 1
                    obj.x = min
                    obj.width = width
                    deleted[obj2.id] = true  
                  }
                }
              }
              if (((obj.direction === 'NORTH') || (obj.direction === 'SOUTH')) && ((obj2.direction === 'NORTH') || (obj2.direction === 'SOUTH'))) {
                if ((obj.x === obj2.x) && (obj.width === obj2.width)) {
                  if (intersect1D(obj.y, obj.y + obj.height, obj2.y, obj2.y + obj2.height)) {
                    min = Math.min(obj.y, obj2.y)
                    max = Math.max(obj.y + obj.height, obj2.y + obj2.height)
                    const height = (max - min) + 1
                    obj.y = min
                    obj.height = height
                    deleted[obj2.id] = true  
                  }
                }
              }
            }
          }
        }
      }
    }
    let idx = this.objects.length - 1
    return (() => {
      const result = []
      while (idx >= 0) {
        const { id } = this.objects[idx]
        if (deleted[id]) {
          this._removeEntity(this.objects[idx])
        }
        result.push(idx--)
      }
      return result
    })()
  }
_mergeTunnels ( ) { const deleted = { } for ( let obj of Array . from ( this . objects ) ) { for ( let obj2 of Array . from ( this . objects ) ) { if ( ! ( deleted [ obj2 . id ] || deleted [ obj . id ] ) ) { if ( obj . id > obj2 . id ) { if ( ( obj . type === 'tunnel' ) && ( obj2 . type === 'tunnel' ) ) { var max , min , width if ( ( ( obj . direction === 'EAST' ) || ( obj . direction === 'WEST' ) ) && ( ( obj2 . direction === 'EAST' ) || ( obj2 . direction === 'WEST' ) ) ) { if ( ( obj . y === obj2 . y ) && ( obj . height === obj2 . height ) ) { if ( intersect1D ( obj . x , obj . x + obj . width , obj2 . x , obj2 . x + obj2 . width ) ) { min = Math . min ( obj . x , obj2 . x ) max = Math . max ( obj . x + obj . width , obj2 . x + obj2 . width ) width = ( max - min ) + 1 obj . x = min obj . width = width deleted [ obj2 . id ] = true } } } if ( ( ( obj . direction === 'NORTH' ) || ( obj . direction === 'SOUTH' ) ) && ( ( obj2 . direction === 'NORTH' ) || ( obj2 . direction === 'SOUTH' ) ) ) { if ( ( obj . x === obj2 . x ) && ( obj . width === obj2 . width ) ) { if ( intersect1D ( obj . y , obj . y + obj . height , obj2 . y , obj2 . y + obj2 . height ) ) { min = Math . min ( obj . y , obj2 . y ) max = Math . max ( obj . y + obj . height , obj2 . y + obj2 . height ) const height = ( max - min ) + 1 obj . y = min obj . height = height deleted [ obj2 . id ] = true } } } } } } } } let idx = this . objects . length - 1 return ( ( ) => { const result = [ ] while ( idx >= 0 ) { const { id } = this . objects [ idx ] if ( deleted [ id ] ) { this . _removeEntity ( this . objects [ idx ] ) } result . push ( idx -- ) } return result } ) ( ) }
combine compatible tunnels (same direction, tunnelWidth, and position)
combine compatible tunnels ( same direction tunnelWidth and position )
// they overlap, take the min/max extents // TODO: connect all of obj2's neighbors to obj // mark object 2 as removed // they overlap, take the min/max extents // TODO: connect all of obj2's neighbors to obj // mark object 2 as removed // remove all the tunnels marked for deletion