Normally if I want to transfer data from double array of fixed length index to single array (or vice versa), I would code something like:
for( int i=0; i<width; i++ ){
for( int j=0; j<height; j++ ){
index = i * Width + j;
singleArray[index] = doubleArray[i][j];
}
}
This obviously wouldn't work if the height (or width) is of varying length.
For varying length i've had to write the code below. It works well but looks very convoluted with too many helper variables. I think there must be a more straight forward line of code that should do the same. Is there?
Just trying to avoid writing dumb code
Java, but here I'm sure the language doesn't matters
int rb=0, prevRb=0, culm=0, addOnce=0;
for(int t=0; t<FloatXArry.size(); t++){ //FIXED SIZE
addOnce = 0;
for(int s=0; s<Height[t]; s++){ //VARYING SIZE
if( (addOnce == 0) && (t>0) ){
rb = rb + 1;
prevRb = rb;
addOnce = 1;
}
rb = prevRb + s;
....
....
ObjFloatArray[t][s] = ArrayObj.get( rb )[0];
}
}