I know that a room must be enclosed on all sides and to roof it there must be a wall within 8 squares, but how is it actually determined that an area is enclosed? Is this something that is known? I'm working on something and would like to know the logic. Interested to see if there's anything different about rooms within rooms and build order.
you can read entire logic behind "rooms" inside game source, you can get information about "how to get source" from sticky threads in this and parent branches of forum.
tldr
enclosed area, roof is optional, full blocks and doors counts.