Guest User

Untitled

a guest
Mar 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. void Swap(ref float lhs, ref float rhs)
  2. {
  3. float tmp = lhs;
  4. lhs = rhs;
  5. rhs = tmp;
  6. }
  7.  
  8. void InplaceFlipX(float[,] arr)
  9. {
  10. int rowLength = arr.GetLength(1);
  11. for (int ix = 0; ix < arr.GetLength(0); ix++) // rows
  12. for (int jx = 0; jx < rowLength / 2; jx++) // columns
  13. Swap(ref arr[ix, jx], ref arr[ix, rowLength - jx - 1]);
  14. }
  15.  
  16. void InplaceFlipY(float[,] arr)
  17. {
  18. int columnLength = arr.GetLength(0);
  19. for (int ix = 0; ix < arr.GetLength(1); ix++) // rows
  20. for (int jx = 0; jx < columnLength / 2; jx++) // columns
  21. Swap(ref arr[jx, ix], ref arr[columnLength - jx - 1, ix]);
  22. }
  23.  
  24. private void InplaceFlipX(float[,,] arr)
  25. {
  26. int rowLength = arr.GetLength(1);
  27. for (int ix = 0; ix < arr.GetLength(0); ix++) // rows
  28. for (int jx = 0; jx < rowLength / 2; jx++) // columns
  29. for (int kx = 0; kx < arr.GetLength(2); kx++)
  30. Swap(ref arr[ix, jx, kx], ref arr[ix, rowLength - jx - 1, kx]);
  31. }
  32.  
  33. private void InplaceFlipY(float[,,] arr)
  34. {
  35. int columnLength = arr.GetLength(0);
  36. for (int ix = 0; ix < arr.GetLength(1); ix++) // rows
  37. for (int jx = 0; jx < columnLength / 2; jx++) // columns
  38. for (int kx = 0; kx < arr.GetLength(2); kx++)
  39. Swap(ref arr[jx, ix, kx], ref arr[columnLength - jx - 1, ix, kx]);
  40. }
  41.  
  42.  
  43. void Main()
  44. {
  45. var foo = new float[2, 3]
  46. {
  47. {1,2,3},
  48. {4,5,6},
  49. };
  50.  
  51. foo.Dump();
  52. InplaceFlipX(foo);
  53. foo.Dump();
  54. InplaceFlipY(foo);
  55. foo.Dump();
  56.  
  57. var boo = new float [2,3,2] {
  58. { {1,2}, {2,3}, {3,4} },
  59. { {4,5}, {5,6}, {6,7} },
  60. };
  61.  
  62. boo.Dump();
  63. InplaceFlipX(boo);
  64. boo.Dump();
  65. InplaceFlipY(boo);
  66. boo.Dump();
  67.  
  68. }
Add Comment
Please, Sign In to add comment