I want to create a 2-d array in Scala. This array partitions a 2-d space into N blocks. Each element of this array has a minX,maxX, minY, and maxY values and an index (from 0 to N^2-1).
For example, if N=8, I want to create indices from 0 to 63, and each index corresponds to a range in space. If I have the minX, maxX, minY, maxY of the whole space, is there any way to use Scala's Range class to provide a step value in both x and y dimensions and create this array with index and individual ranges?
This is the class and function I am creating:
class Grid (index: Int, minX: Double, minY: Double, maxX: Double, maxY: Double){
def buildgrid(spaceminX: Double, spaceminY: Double, spacemaxX: Double, spacemaxY: Double,num_partitions:Int): Unit =
{
val stepX=spacemaxX-spaceminX/num_partitions
val stepY=spacemaxY-spaceminY/num_partitions
???
}}
Here, the variables prefixed with space are the values for the whole space that needs to be divided into N blocks. I am stuck at how to create the array in the function. The expected output of this array would be: Array[(0,minX,maxX,minY,maxY),(1, minX,maxX, minY, maxY)...,(63, minX,maxX,minY,maxY)]