Neighbours.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. namespace libTerrain
  29. {
  30. partial class Channel
  31. {
  32. private enum NeighbourSystem
  33. {
  34. Moore,
  35. VonNeumann
  36. } ;
  37. private int[] Neighbours(NeighbourSystem type, int index)
  38. {
  39. int[] coord = new int[2];
  40. index++;
  41. switch (type)
  42. {
  43. case NeighbourSystem.Moore:
  44. switch (index)
  45. {
  46. case 1:
  47. coord[0] = -1;
  48. coord[1] = -1;
  49. break;
  50. case 2:
  51. coord[0] = -0;
  52. coord[1] = -1;
  53. break;
  54. case 3:
  55. coord[0] = +1;
  56. coord[1] = -1;
  57. break;
  58. case 4:
  59. coord[0] = -1;
  60. coord[1] = -0;
  61. break;
  62. case 5:
  63. coord[0] = -0;
  64. coord[1] = -0;
  65. break;
  66. case 6:
  67. coord[0] = +1;
  68. coord[1] = -0;
  69. break;
  70. case 7:
  71. coord[0] = -1;
  72. coord[1] = +1;
  73. break;
  74. case 8:
  75. coord[0] = -0;
  76. coord[1] = +1;
  77. break;
  78. case 9:
  79. coord[0] = +1;
  80. coord[1] = +1;
  81. break;
  82. default:
  83. break;
  84. }
  85. break;
  86. case NeighbourSystem.VonNeumann:
  87. switch (index)
  88. {
  89. case 1:
  90. coord[0] = 0;
  91. coord[1] = -1;
  92. break;
  93. case 2:
  94. coord[0] = -1;
  95. coord[1] = 0;
  96. break;
  97. case 3:
  98. coord[0] = +1;
  99. coord[1] = 0;
  100. break;
  101. case 4:
  102. coord[0] = 0;
  103. coord[1] = +1;
  104. break;
  105. case 5:
  106. coord[0] = -0;
  107. coord[1] = -0;
  108. break;
  109. default:
  110. break;
  111. }
  112. break;
  113. }
  114. return coord;
  115. }
  116. }
  117. }