Skip to content

Instantly share code, notes, and snippets.

Finding Room Overlap using the principles of AABB

Introduction

Storing your rooms and rectangles is a very powerful and common practice to build levels and define maps. You may store the Rect in a varierty of ways such as {top, left, bottom, right} or {x, y, height, width}. This structure can be useful for many things such as moving rooms around during generation (pushing/expansion type algorithms), creating graphs such as Min Spanning Treets, or as the general output of a generator like a BSP.

In this guide I will use {top, left, bottom, right} as the Rect structure for berevity but any structure for defining a rectangle could work.

I will also assume an origin of the top left of the screen. I.e on the screen a larger Y value is further "down" and a larger x value is further right on the map.

For this article I will also try to spell out considerations for conceptualizing a room as being empty in its entire contents versus having a 1 tile ring of walls around it. (i.e. in the former style a ro