The city in my game is randomly generated, but it is a graph of roads and intersections that only rectangles can form:

As you can see, my landscape is pretty empty. I want to find each empty rectangle and save it in the list of rectangles, forming lots.

As you can see in this illustration, I filled in 3 'lots', and in 1 I showed 3 rectangles of which it is made.
My data structures:
package com.jkgames.gta; import android.graphics.Bitmap; import android.graphics.RectF; public class Intersection extends Entity { Road topRoad; Road leftRoad; Road bottomRoad; Road rightRoad; Bitmap image; public Bitmap getImage() { return image; } public void setImage(Bitmap image) { this.image = image; } public Intersection(RectF rect, Bitmap image) { setRect(rect); setImage(image); } public Road getTopRoad() { return topRoad; } public void setTopRoad(Road topRoad) { this.topRoad = topRoad; } public Road getLeftRoad() { return leftRoad; } public void setLeftRoad(Road leftRoad) { this.leftRoad = leftRoad; } public Road getBottomRoad() { return bottomRoad; } public void setBottomRoad(Road bottomRoad) { this.bottomRoad = bottomRoad; } public Road getRightRoad() { return rightRoad; } public void setRightRoad(Road rightRoad) { this.rightRoad = rightRoad; } @Override public void draw(GraphicsContext c) { c.drawRotatedScaledBitmap(image, getCenterX(), getCenterY(), getWidth(), getHeight(), getAngle()); } } public class Road extends Entity { private Bitmap image = null; private Intersection startIntersection; private Intersection endIntersection; private boolean topBottom; public Road(RectF rect, Intersection start, Intersection end, Bitmap image, boolean topBottom) { setRect(rect); setStartIntersection(start); setEndIntersection(end); setImage(image); setTopBottom(topBottom); } @Override public void draw(GraphicsContext c) {
A city is a list of roads and intersections.
Is there any algorithm that could generate these lots and their rectangles?
thanks
source share