How to find the number of polygons enclosed by preview lines and walls?

Hi guys I am new to Revit and Dynamo. I need to assist a task to automatically optimize floor tile layouts for rooms. The attached image shows a sample project with random walls. I wrote a script to create preview lines to show how the tiles would be arranged. I can pick a straight wall and start the grid from there, as well as select a rotation angle for the start axis.

My question is, after creating lines like this, what can I do to calculate the total number of tiles (squares) used that are enclosed by the walls within the room?

After solving this, the more advanced thing is to use as much of a single tile as I can, i.e. use one tile for multiple small polygons on the edges. What are possible approaches to do this?

Sorry if I describe it poorly or my question is too basic. Thanks!

@James_BIM ,
try to look here:

and here: