Neighbours.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. namespace libTerrain
  28. {
  29. partial class Channel
  30. {
  31. private enum NeighbourSystem
  32. {
  33. Moore,
  34. VonNeumann
  35. } ;
  36. private int[] Neighbours(NeighbourSystem type, int index)
  37. {
  38. int[] coord = new int[2];
  39. index++;
  40. switch (type)
  41. {
  42. case NeighbourSystem.Moore:
  43. switch (index)
  44. {
  45. case 1:
  46. coord[0] = -1;
  47. coord[1] = -1;
  48. break;
  49. case 2:
  50. coord[0] = -0;
  51. coord[1] = -1;
  52. break;
  53. case 3:
  54. coord[0] = +1;
  55. coord[1] = -1;
  56. break;
  57. case 4:
  58. coord[0] = -1;
  59. coord[1] = -0;
  60. break;
  61. case 5:
  62. coord[0] = -0;
  63. coord[1] = -0;
  64. break;
  65. case 6:
  66. coord[0] = +1;
  67. coord[1] = -0;
  68. break;
  69. case 7:
  70. coord[0] = -1;
  71. coord[1] = +1;
  72. break;
  73. case 8:
  74. coord[0] = -0;
  75. coord[1] = +1;
  76. break;
  77. case 9:
  78. coord[0] = +1;
  79. coord[1] = +1;
  80. break;
  81. default:
  82. break;
  83. }
  84. break;
  85. case NeighbourSystem.VonNeumann:
  86. switch (index)
  87. {
  88. case 1:
  89. coord[0] = 0;
  90. coord[1] = -1;
  91. break;
  92. case 2:
  93. coord[0] = -1;
  94. coord[1] = 0;
  95. break;
  96. case 3:
  97. coord[0] = +1;
  98. coord[1] = 0;
  99. break;
  100. case 4:
  101. coord[0] = 0;
  102. coord[1] = +1;
  103. break;
  104. case 5:
  105. coord[0] = -0;
  106. coord[1] = -0;
  107. break;
  108. default:
  109. break;
  110. }
  111. break;
  112. }
  113. return coord;
  114. }
  115. }
  116. }