I am working on some functions to use in my enemy state machines.

I want to write a function which determines whether the platform the enemy is standing on is connected to the platform the player is standing on.

Platforms have associated rectangles, and by *connected*, I mean there is a *chain* of rectangles from the first rectangle to the second rectangle.

Here's an illustration:

[![enter image description here](https://i.stack.imgur.com/cKcKL.png)](https://i.stack.imgur.com/cKcKL.png)

Here are my assumptions:

1. The rectangles contain their perimeters.
2. Two rectangles touching only on their perimeter are connected.
3. Two rectangles overlapping are connected.
4. The rectangles are guaranteed to be axis-aligned.
5. The rectangles will be at integer coordinates (the grid is 1x1).
6. Every rectangle has attributes like topleft, bottomright, etc.
7. Directly connected rectangles won't necessarily have any corners in common.

My question: **What is an efficient way to determine the connectedness of rectangles in 2D space?**

---

**NOTE:**
I asked a more specific version of this question in a Godot forum, but given that this is a general game dev question, I figured I'd ask this variation here.