My first approach was to use simple array like:
int[,] map = new int[numSectors, numScreens, numPoints];
But this lead me to situation where I don’t know for sure how many Points are there in particular Screen, since map.GetLength(2) always will return numPoints while there could be “empty” elements for this particular part of array.
As per my example above I cannot reference to map[0, 0, 7] (because there’s only 6 elements), but I can easily access map[0, 1, 7] (because there are 25 elements).
public class Map
{
IList<Sector> Sectors { get; } = new List<Sector>();
}
public class Sector
{
IList<Screen> Screens { get; } = new List<Screen>(6);
}
public class Screen
{
IList<Point> Points { get; } = new List<Point>(25);
}
public class Point
{
// not clear what information a point holds
}
public void SomeFunction()
{
var Map = // ... initialize the map here
foreach (var sector in Map.Sectors)
foreach (var screen in sector.Screens)
foreach (var point in screen.Points)
// .. do something with point
// alternatively
for (int i = 0; i < Map.Sectors.Count)
for (int j = 0; j < Map.Sectors[i].Screens.Count)
for (int k = 0; k < Map.Sectors[i].Screens[j].Points.Count)
// do something with Map.Sectors[i].Screens[j].Points[k]
}
Yes. This is one way to implement spatial partitioning. If you want to read more about spatial partitioning in general and see some example images, check Wikipedia’s Quadtree page.