FixedArray.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Farseer Physics Engine based on Box2D.XNA port:
  3. * Copyright (c) 2010 Ian Qvist
  4. *
  5. * Box2D.XNA port of Box2D:
  6. * Copyright (c) 2009 Brandon Furtwangler, Nathan Furtwangler
  7. *
  8. * Original source Box2D:
  9. * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
  10. *
  11. * This software is provided 'as-is', without any express or implied
  12. * warranty. In no event will the authors be held liable for any damages
  13. * arising from the use of this software.
  14. * Permission is granted to anyone to use this software for any purpose,
  15. * including commercial applications, and to alter it and redistribute it
  16. * freely, subject to the following restrictions:
  17. * 1. The origin of this software must not be misrepresented; you must not
  18. * claim that you wrote the original software. If you use this software
  19. * in a product, an acknowledgment in the product documentation would be
  20. * appreciated but is not required.
  21. * 2. Altered source versions must be plainly marked as such, and must not be
  22. * misrepresented as being the original software.
  23. * 3. This notice may not be removed or altered from any source distribution.
  24. */
  25. using System;
  26. namespace FarseerPhysics.Common
  27. {
  28. public struct FixedArray2<T>
  29. {
  30. private T _value0;
  31. private T _value1;
  32. public T this[int index]
  33. {
  34. get
  35. {
  36. switch (index)
  37. {
  38. case 0:
  39. return _value0;
  40. case 1:
  41. return _value1;
  42. default:
  43. throw new IndexOutOfRangeException();
  44. }
  45. }
  46. set
  47. {
  48. switch (index)
  49. {
  50. case 0:
  51. _value0 = value;
  52. break;
  53. case 1:
  54. _value1 = value;
  55. break;
  56. default:
  57. throw new IndexOutOfRangeException();
  58. }
  59. }
  60. }
  61. }
  62. public struct FixedArray3<T>
  63. {
  64. private T _value0;
  65. private T _value1;
  66. private T _value2;
  67. public T this[int index]
  68. {
  69. get
  70. {
  71. switch (index)
  72. {
  73. case 0:
  74. return _value0;
  75. case 1:
  76. return _value1;
  77. case 2:
  78. return _value2;
  79. default:
  80. throw new IndexOutOfRangeException();
  81. }
  82. }
  83. set
  84. {
  85. switch (index)
  86. {
  87. case 0:
  88. _value0 = value;
  89. break;
  90. case 1:
  91. _value1 = value;
  92. break;
  93. case 2:
  94. _value2 = value;
  95. break;
  96. default:
  97. throw new IndexOutOfRangeException();
  98. }
  99. }
  100. }
  101. }
  102. public struct FixedArray4<T>
  103. {
  104. private T _value0;
  105. private T _value1;
  106. private T _value2;
  107. private T _value3;
  108. public T this[int index]
  109. {
  110. get
  111. {
  112. switch (index)
  113. {
  114. case 0:
  115. return _value0;
  116. case 1:
  117. return _value1;
  118. case 2:
  119. return _value2;
  120. case 3:
  121. return _value3;
  122. default:
  123. throw new IndexOutOfRangeException();
  124. }
  125. }
  126. set
  127. {
  128. switch (index)
  129. {
  130. case 0:
  131. _value0 = value;
  132. break;
  133. case 1:
  134. _value1 = value;
  135. break;
  136. case 2:
  137. _value2 = value;
  138. break;
  139. case 3:
  140. _value3 = value;
  141. break;
  142. default:
  143. throw new IndexOutOfRangeException();
  144. }
  145. }
  146. }
  147. }
  148. public struct FixedArray8<T>
  149. {
  150. private T _value0;
  151. private T _value1;
  152. private T _value2;
  153. private T _value3;
  154. private T _value4;
  155. private T _value5;
  156. private T _value6;
  157. private T _value7;
  158. public T this[int index]
  159. {
  160. get
  161. {
  162. switch (index)
  163. {
  164. case 0:
  165. return _value0;
  166. case 1:
  167. return _value1;
  168. case 2:
  169. return _value2;
  170. case 3:
  171. return _value3;
  172. case 4:
  173. return _value4;
  174. case 5:
  175. return _value5;
  176. case 6:
  177. return _value6;
  178. case 7:
  179. return _value7;
  180. default:
  181. throw new IndexOutOfRangeException();
  182. }
  183. }
  184. set
  185. {
  186. switch (index)
  187. {
  188. case 0:
  189. _value0 = value;
  190. break;
  191. case 1:
  192. _value1 = value;
  193. break;
  194. case 2:
  195. _value2 = value;
  196. break;
  197. case 3:
  198. _value3 = value;
  199. break;
  200. case 4:
  201. _value4 = value;
  202. break;
  203. case 5:
  204. _value5 = value;
  205. break;
  206. case 6:
  207. _value6 = value;
  208. break;
  209. case 7:
  210. _value7 = value;
  211. break;
  212. default:
  213. throw new IndexOutOfRangeException();
  214. }
  215. }
  216. }
  217. }
  218. }