Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Swap(ref float lhs, ref float rhs)
- {
- float tmp = lhs;
- lhs = rhs;
- rhs = tmp;
- }
- void InplaceFlipX(float[,] arr)
- {
- int rowLength = arr.GetLength(1);
- for (int ix = 0; ix < arr.GetLength(0); ix++) // rows
- for (int jx = 0; jx < rowLength / 2; jx++) // columns
- Swap(ref arr[ix, jx], ref arr[ix, rowLength - jx - 1]);
- }
- void InplaceFlipY(float[,] arr)
- {
- int columnLength = arr.GetLength(0);
- for (int ix = 0; ix < arr.GetLength(1); ix++) // rows
- for (int jx = 0; jx < columnLength / 2; jx++) // columns
- Swap(ref arr[jx, ix], ref arr[columnLength - jx - 1, ix]);
- }
- private void InplaceFlipX(float[,,] arr)
- {
- int rowLength = arr.GetLength(1);
- for (int ix = 0; ix < arr.GetLength(0); ix++) // rows
- for (int jx = 0; jx < rowLength / 2; jx++) // columns
- for (int kx = 0; kx < arr.GetLength(2); kx++)
- Swap(ref arr[ix, jx, kx], ref arr[ix, rowLength - jx - 1, kx]);
- }
- private void InplaceFlipY(float[,,] arr)
- {
- int columnLength = arr.GetLength(0);
- for (int ix = 0; ix < arr.GetLength(1); ix++) // rows
- for (int jx = 0; jx < columnLength / 2; jx++) // columns
- for (int kx = 0; kx < arr.GetLength(2); kx++)
- Swap(ref arr[jx, ix, kx], ref arr[columnLength - jx - 1, ix, kx]);
- }
- void Main()
- {
- var foo = new float[2, 3]
- {
- {1,2,3},
- {4,5,6},
- };
- foo.Dump();
- InplaceFlipX(foo);
- foo.Dump();
- InplaceFlipY(foo);
- foo.Dump();
- var boo = new float [2,3,2] {
- { {1,2}, {2,3}, {3,4} },
- { {4,5}, {5,6}, {6,7} },
- };
- boo.Dump();
- InplaceFlipX(boo);
- boo.Dump();
- InplaceFlipY(boo);
- boo.Dump();
- }
Add Comment
Please, Sign In to add comment