int3.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* The MIT License
  2. *
  3. * Copyright (c) 2010 Intel Corporation.
  4. * All rights reserved.
  5. *
  6. * Based on the convexdecomposition library from
  7. * <http://codesuppository.googlecode.com> by John W. Ratcliff and Stan Melax.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. using System;
  28. namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
  29. {
  30. public class int3
  31. {
  32. public int x;
  33. public int y;
  34. public int z;
  35. public int3()
  36. {
  37. }
  38. public int3(int _x, int _y, int _z)
  39. {
  40. x = _x;
  41. y = _y;
  42. z = _z;
  43. }
  44. public int this[int i]
  45. {
  46. get
  47. {
  48. switch (i)
  49. {
  50. case 0: return x;
  51. case 1: return y;
  52. case 2: return z;
  53. }
  54. throw new ArgumentOutOfRangeException();
  55. }
  56. set
  57. {
  58. switch (i)
  59. {
  60. case 0: x = value; return;
  61. case 1: y = value; return;
  62. case 2: z = value; return;
  63. }
  64. throw new ArgumentOutOfRangeException();
  65. }
  66. }
  67. public override int GetHashCode()
  68. {
  69. return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
  70. }
  71. public override bool Equals(object obj)
  72. {
  73. int3 i = obj as int3;
  74. if (i == null)
  75. return false;
  76. return this == i;
  77. }
  78. public static bool operator ==(int3 a, int3 b)
  79. {
  80. // If both are null, or both are same instance, return true.
  81. if (System.Object.ReferenceEquals(a, b))
  82. return true;
  83. // If one is null, but not both, return false.
  84. if (((object)a == null) || ((object)b == null))
  85. return false;
  86. for (int i = 0; i < 3; i++)
  87. {
  88. if (a[i] != b[i])
  89. return false;
  90. }
  91. return true;
  92. }
  93. public static bool operator !=(int3 a, int3 b)
  94. {
  95. return !(a == b);
  96. }
  97. public static int3 roll3(int3 a)
  98. {
  99. int tmp = a[0];
  100. a[0] = a[1];
  101. a[1] = a[2];
  102. a[2] = tmp;
  103. return a;
  104. }
  105. public static bool isa(int3 a, int3 b)
  106. {
  107. return (a == b || roll3(a) == b || a == roll3(b));
  108. }
  109. public static bool b2b(int3 a, int3 b)
  110. {
  111. return isa(a, new int3(b[2], b[1], b[0]));
  112. }
  113. }
  114. }