Here is my solution.
First I created a Google sheets to help me map out the chunks and tiles with their coordinates, what I want and what I get from my current iteration code:

I want to iterate over the green tiles, across multiple chunks and receive the correct tile coordinates and chunk coordinates, with only the building Width, Height, start tile X,Y and chunk start X,Y.
This allowed me to finally come up with a working solution (below), which is fast.
Note: To get this solution working quickly I have a lot of code in class constructors, this is not advisable and I will refactor later when I move this solution into my main project.
I used https://csharppad.com/ to quickly test the following code, which can be pasted in the "interactive shell" panel, then click "Go":
class World
{
public Chunk[][] Chunks;
public int ChunkSizeTilesXY = 3;
public World()
{
Chunks = new Chunk[3][];
for (int x = 0; x < 3; x++)
{
Chunks[x] = new Chunk[3];
for (int y = 0; y < 3; y++)
{
Chunks[x][y] = new Chunk()
{
chunkX = x,
chunkY = y
};
}
}
Test();
}
private void Test(){
int buildingWidthInTiles = 2;
int buildingHeightInTiles = 3;
int startTileX = 2;
int startTileY = 2;
int endTileX = startTileX + buildingWidthInTiles;
int endTileY = startTileY + buildingHeightInTiles;
int startChunkX = 0;
int startChunkY = 0;
int chunkX = startChunkX;
int chunkY = startChunkY;
int ctx = startTileX;
int cty = startTileY;
for (int tx = startTileX; tx < endTileX; tx++)
{
// Out of bounds of current chunk, increment chunk and ctx (chunk tile x)
if (ctx > ChunkSizeTilesXY-1)
{
chunkX++;
ctx = 0;
}
for (int ty = startTileY; ty < endTileY; ty++)
{
// Out of bounds of current chunk, increment chunk and cty (chunk tile y)
if (cty > ChunkSizeTilesXY-1)
{
chunkY++;
cty = 0;
}
Chunks[chunkX][chunkY].Tiles[ctx][cty].IsBuiltOn = true;
Console.WriteLine("tx:" + tx + ", ty: " + ty + ", ctx:" + ctx + ", cty: " + cty + ", chunkX: " + chunkX + ", chunkY:" + chunkY);
cty++;
}
ctx++;
// Reset chunkY
chunkY = startChunkY;
}
// Reset chunkX
chunkX = startChunkX;
}
}
class Chunk
{
public Tile[][] Tiles;
public int chunkX;
public int chunkY;
public Chunk()
{
Tiles = new Tile[3][];
for (int x = 0; x < 3; x++)
{
Tiles[x] = new Tile[3];
for (int y = 0; y < 3; y++)
{
Tiles[x][y] = new Tile()
{
chunkX = chunkX,
chunkY = chunkY
};
}
}
}
}
class Tile
{
public bool IsBuiltOn = false;
public int chunkX;
public int chunkY;
public Tile()
{
}
}
var world = new World();
I am still interested in hearing from others on alternate or faster solutions.