Point3D.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.util;
  16. import java.io.Serializable;
  17. /**
  18. * This class ...
  19. * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
  20. */
  21. public class Point3D implements Serializable
  22. {
  23. /**
  24. * Comment for <code>serialVersionUID</code>
  25. */
  26. private static final long serialVersionUID = 4638345252031872576L;
  27. private volatile int _x, _y, _z;
  28. public Point3D(int pX, int pY, int pZ)
  29. {
  30. _x = pX;
  31. _y = pY;
  32. _z = pZ;
  33. }
  34. public Point3D(int pX, int pY)
  35. {
  36. _x = pX;
  37. _y = pY;
  38. _z = 0;
  39. }
  40. /**
  41. * @param worldPosition
  42. */
  43. public Point3D(Point3D worldPosition)
  44. {
  45. _x = worldPosition._x;
  46. _y = worldPosition._y;
  47. _z = worldPosition._z;
  48. }
  49. public synchronized void setTo(Point3D point)
  50. {
  51. _x = point._x;
  52. _y = point._y;
  53. _z = point._z;
  54. }
  55. @Override
  56. public String toString()
  57. {
  58. return "(" + _x + ", " + _y + ", " + _z + ")";
  59. }
  60. @Override
  61. public int hashCode()
  62. {
  63. return _x ^ _y ^ _z;
  64. }
  65. @Override
  66. public boolean equals(Object o)
  67. {
  68. if (this == o)
  69. {
  70. return true;
  71. }
  72. if (o instanceof Point3D)
  73. {
  74. Point3D point3D = (Point3D) o;
  75. boolean ret = (point3D._x == _x) && (point3D._y == _y) && (point3D._z == _z);
  76. return ret;
  77. }
  78. return false;
  79. }
  80. public boolean equals(int pX, int pY, int pZ)
  81. {
  82. return (_x == pX) && (_y == pY) && (_z == pZ);
  83. }
  84. public long distanceSquaredTo(Point3D point)
  85. {
  86. long dx, dy;
  87. dx = _x - point._x;
  88. dy = _y - point._y;
  89. return (dx * dx) + (dy * dy);
  90. }
  91. public static long distanceSquared(Point3D point1, Point3D point2)
  92. {
  93. long dx, dy;
  94. dx = point1._x - point2._x;
  95. dy = point1._y - point2._y;
  96. return (dx * dx) + (dy * dy);
  97. }
  98. public static boolean distanceLessThan(Point3D point1, Point3D point2, double distance)
  99. {
  100. return distanceSquared(point1, point2) < (distance * distance);
  101. }
  102. public int getX()
  103. {
  104. return _x;
  105. }
  106. public synchronized void setX(int pX)
  107. {
  108. _x = pX;
  109. }
  110. public int getY()
  111. {
  112. return _y;
  113. }
  114. public synchronized void setY(int pY)
  115. {
  116. _y = pY;
  117. }
  118. public int getZ()
  119. {
  120. return _z;
  121. }
  122. public synchronized void setZ(int pZ)
  123. {
  124. _z = pZ;
  125. }
  126. public synchronized void setXYZ(int pX, int pY, int pZ)
  127. {
  128. _x = pX;
  129. _y = pY;
  130. _z = pZ;
  131. }
  132. }