example/bundle.js
// determine the largest room that fits at the given level position
determine the largest room that fits at the given level position
determine the largest room that fits at the given level position
findLargestRoom(doorPosition, direction, maxSize) {
    const leftDirection = turn90(direction, 'LEFT')
    const rightDirection = turn90(direction, 'RIGHT')
    const directionVectors = {
      forward: direction,
      left: leftDirection,
      right: rightDirection
    }
    const expand = {forward: true, left: true, right: true}
    let result = { x: doorPosition.x, y: doorPosition.y, width: 1, height: 1 }
    moveAABB(result, directionVectors.forward)
    const minTunnelSpacing = 1
    const minAnteroomSpacing = 1
    while (expand.left || expand.right || expand.forward) {
      for (let dir in expand) {
        const exp = expand[dir]
        if (exp) {
          const cardinalDirection = directionVectors[dir]
          const test = expandAABB(result, cardinalDirection)
          if ((test.width * test.height) > maxSize) {
            return result
          }
          if ((test.width / test.height) < this.design.roomAspectRatio) {
            return result
          }
          if ((test.height / test.width) < this.design.roomAspectRatio) {
            return result
          }
          if (!this.contains(test)) {
            expand[dir] = false
          } else {
            if (this.overlaps(test, this.design.minRoomSpacing, minAnteroomSpacing, minTunnelSpacing)) {
              expand[dir] = false
            } else {
              result = test
            }
          }
        }
      }
    }
    return result
  }
findLargestRoom ( doorPosition , direction , maxSize ) { const leftDirection = turn90 ( direction , 'LEFT' ) const rightDirection = turn90 ( direction , 'RIGHT' ) const directionVectors = { forward : direction , left : leftDirection , right : rightDirection } const expand = { forward : true , left : true , right : true } let result = { x : doorPosition . x , y : doorPosition . y , width : 1 , height : 1 } moveAABB ( result , directionVectors . forward ) const minTunnelSpacing = 1 const minAnteroomSpacing = 1 while ( expand . left || expand . right || expand . forward ) { for ( let dir in expand ) { const exp = expand [ dir ] if ( exp ) { const cardinalDirection = directionVectors [ dir ] const test = expandAABB ( result , cardinalDirection ) if ( ( test . width * test . height ) > maxSize ) { return result } if ( ( test . width / test . height ) < this . design . roomAspectRatio ) { return result } if ( ( test . height / test . width ) < this . design . roomAspectRatio ) { return result } if ( ! this . contains ( test ) ) { expand [ dir ] = false } else { if ( this . overlaps ( test , this . design . minRoomSpacing , minAnteroomSpacing , minTunnelSpacing ) ) { expand [ dir ] = false } else { result = test } } } } } return result }
determine the largest room that fits at the given level position
determine the largest room that fits at the given level position
// move to the first position in the room (right in front of the door) // Grow in all directions from the door. When overlapping or adjacent to an // object, stop growing in that direction. When growing stops in all // directions, we've found the largest room that fits in this area. // ensure room aspect ratio are within acceptable limits // expanded outside of level dimensions, reject this expansion