Maybe one of you guys can help me with this. here is the function.
bool GetSubArray(unsigned int X, unsigned int Y, unsigned int Width, unsigned int Height, TArray2D<T> &ArrayOut, unsigned int &WidthOut, unsigned int &HeightOut) { // check to see if X or Y is to large for array if ((X > mDimX)||(Y > mDimY)) { WidthOut = 0; HeightOut = 0; return true; } // check to see if we over run the array and set Height and Width if (((X+Width)-1) >= mDimX) // to many wide { Width -= (Width - mDimX); } else { Width = (X + Width); } if (((Y+Height)-1) >= mDimY) // to many high { Height -= (Height - mDimY); } else { Height = (Y + Height); } // set the out Height and Width WidthOut = (Width - X); HeightOut = (Height - Y); // clear the array passed in ArrayOut.Destroy(); ArrayOut.Initialize(WidthOut, HeightOut, T()); // loop through and fill subarray with array unsigned int IndexX = 0; unsigned int IndexY = 0; for (unsigned int iy = Y; iy < Height; ++iy) { for (unsigned int ix = X; ix < Width; ++ix) { ArrayOut.SetValue(IndexX, IndexY, GetValue(ix,iy)); ++IndexX; } IndexX = 0; ++IndexY; } return false; }
my problem is that if I ask for a square subarray I get the correct subarray back. if I ask for a subarray that is wider then it is High I get the correct array back. but if I ask for an subarray that is higher then it is wide I get strange numbers.
From an array of
0000000000
1111111111
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9999999999
I get
0444
1555
2666
3333
4444
5555
6666
just a clearification i am asking for an array from 0,0 with a width of 4 and a height of 7
I have been knocking my head on the wall for hours. I would thank you for any help.
[Edited by - alchemar on September 29, 2004 9:23:58 AM]