# Class AABB¶

## Class Documentation¶

class AABB

This file defines the members and methods implemented as part of the AABB class.

This class represents an Axis Aligned Bounding Box as seen from the top-view of the Minecraft X-Z plane.

Subclassed by Group, ZombieworldPit

Public Functions

std::string getID()

Get the AABB’s id.

Return

int The id

std::string getMaterial()

Get the AABB’s material.

Return

string The material name

std::string getType()

Get the AABB type.

Return

string The type

Pos getTopLeft()

Returns a copy of the Pos object used to represent the top left of the AABB from the top view of the X-Z plane.

Return

Pos The copy of the top left coordinate

Pos getBottomRight()

Returns a copy of the Pos object used to represent the bottom right of the AABB from the top view of the X-Z plane.

Return

Pos The copy of the bottom right coordinate

std::vector<Block*> &getBlockList()

Get the block list specific to this AABB.

Return

The reference to the block list

std::vector<Entity*> &getEntityList()

Get the entity list specific to this AABB.

Return

The reference to the entity list

std::vector<Object*> &getObjectList()

Get the object list specific to this AABB.

Return

The reference to the object list

int getMidpointX()

Get the midpoint X value calculated between the top left and bottom right x values.

Return

int The midpoint X coordinate

int getMidpointY()

Get the midpoint Y value calculated between the top left and bottom right y values.

Return

int The midpoint Y coordinate

int getMidpointZ()

Get the midpoint Z value calculated between the top left and bottom right z values.

Return

int The midpoint Z coordinate

int getSizeX()

Get the difference of the extreme x coordinates for this AABB.

Return

int The difference

int getSizeY()

Get the difference of the extreme y coordinates for this AABB.

Return

int The difference

int getSizeZ()

Get the difference of the extreme z coordinates for this AABB.

Return

int The difference

Pos getRandomPos(std::mt19937_64 &gen, int offsetPosX = 0, int offsetNegX = 0, int offsetPosY = 0, int offsetNegY = 0, int offsetPosZ = 0, int offsetNegZ = 0)

Get a random position in the AABB within the given offsets.

Return

Pos The random position

Parameters
• gen: THe boost generation object to generate distributions from

• offsetPosX: How far away from the left wall should the position be. Defaults to 0

• offsetNegX: How far away from the right wall should the position be. Defaults to 0

• offsetPosY: How far away from the left wall should the position be. Defaults to 0

• offsetNegY: How far away from the right wall should the position be. Defaults to 0

• offsetPosZ: How far away from the bottom wall should the position be. Defaults to 0

• offsetNegZ: How far away from the top wall should the position be. Defaults to 0

std::vector<Pos> getEdgeMidpointAtBase()

Get a list of the positions of the edge midpoints for this AABB. The Y value for all these Pos objects is equal to the Y value of the AABB’s top left field which is considered the base.

Return

vector<Pos> The list of coordinates as: top, right, bottom and left edge midpoints.

void setTopLeft(Pos &topLeft)

Set the top left coordinate of the AABB.

Parameters
• topLeft: Pos object top left is to be set to

void setBottomRight(Pos &bottomRight)

Set the bottom right coordinate of the AABB.

Parameters
• bottomRight: Pos object bottom right is to be set to

void setMaterial(std::string material)

Set the base building material.

Parameters
• material: The base material

void addBlock(Block &block)

Add a specific block for this AABB to keep track of. Ideally this should be related to the AABB. No checks are implicitly performed within this method.

Parameters
• block: Block to be added

void addEntity(Entity &entity)

Add a specific entity for this AABB to keep track of. Ideally this should be related to the AABB. No checks are implicitly performed within this method.

Parameters
• entity: Entity to be added

void addObject(Object &object)

Add a specific object for this AABB to keep track of. Ideally this should be related to the AABB. No checks are implicitly performed within this method.

Parameters
• object: Object to be added

bool isOverlapping(AABB &other)

Checks to see if two AABBs overlapp on any of the axes.

Return

true When the AABBs do overlap

Return

false When the AABBs don’t overlap

Parameters
• other: The AABB to compare to

void generateBox(std::string material, int offsetPosX = 0, int offsetNegX = 0, int offsetPosY = 0, int offsetNegY = 0, int offsetPosZ = 0, int offsetNegZ = 0)

Generate a box made of s specific material inside the AABB with the ability to specify offsets.

Parameters
• material: The material to make this box out of

• offsetPosX: How far away from the left wall should the position be. Defaults to 0

• offsetNegX: How far away from the right wall should the position be. Defaults to 0

• offsetPosY: How far away from the left wall should the position be. Defaults to 0

• offsetNegY: How far away from the right wall should the position be. Defaults to 0

• offsetPosZ: How far away from the bottom wall should the position be. Defaults to 0

• offsetNegZ: How far away from the top wall should the position be. Defaults to 0

void addRandomBlocks(int n, std::string material, std::mt19937_64 &gen, int offsetPosX = 0, int offsetNegX = 0, int offsetPosY = 0, int offsetNegY = 0, int offsetPosZ = 0, int offsetNegZ = 0)

Add n random blocks of the given type and material inside the AABB within the offset parameters.

Parameters
• n: The number of blocks to add

• material: The block’s material type

• gen: THe boost generation object to generate distributions from

• offsetPosX: How far away from the left wall should the position be. Defaults to 0

• offsetNegX: How far away from the right wall should the position be. Defaults to 0

• offsetPosY: How far away from the left wall should the position be. Defaults to 0

• offsetNegY: How far away from the right wall should the position be. Defaults to 0

• offsetPosZ: How far away from the bottom wall should the position be. Defaults to 0

• offsetNegZ: How far away from the top wall should the position be. Defaults to 0

void generateAllDoorsInAABB()

Generate 4 doors for the AABB at the midpoint.

void toSemanticMapJSON(nlohmann::json &json_base)

Adds the JSON representation of this object to the “locations” list of the base json.

Return

nlohmann::json The base json

void toLowLevelMapJSON(nlohmann::json &json_base)

Adds the alternate block by block JSON representation of this object to the “blocks” list of the base json.

Return

nlohmann::json The base json

AABB(std::string id, std::string type, std::string material, Pos &topLeft, Pos &bottomRight, bool isHollow = true, bool hasRoof = false)

Construct a new AABB object.

Parameters
• id: The id associated with this AABB

• type: A semantic name describing the type and/or purpose of the AABB

• material: The material this AABB is built out of

• topLeft: The coordinates of the top left of the AABB from the top view of the X-Z plane. Y coordinate should be lowest here.

• bottomRight: The coordinates of the bottom right of the AABB from the top view of the X-Z plane. Y coordinate should be maximum here.

• isHollow: Specify wether the AABB should be hollow or not. Defaults to true.

• hasRoof: specify wether the AABB should have a roof or not. Defaults to false.

~AABB()

Destroy the AABB object.

Protected Attributes

std::string id
std::string material
std::string type
Pos topLeft
Pos bottomRight
bool isHollow
bool hasRoof
std::vector<Block*> blockList
std::vector<Entity*> entityList
std::vector<Object*> objectList