Point3D.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. *
  20. * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
  21. */
  22. public class Point3D implements Serializable
  23. {
  24. /**
  25. * Comment for <code>serialVersionUID</code>
  26. */
  27. private static final long serialVersionUID = 4638345252031872576L;
  28. private volatile int _x, _y, _z;
  29. public Point3D(int pX, int pY, int pZ)
  30. {
  31. _x = pX;
  32. _y = pY;
  33. _z = pZ;
  34. }
  35. public Point3D(int pX, int pY)
  36. {
  37. _x = pX;
  38. _y = pY;
  39. _z = 0;
  40. }
  41. /**
  42. * @param worldPosition
  43. */
  44. public Point3D(Point3D worldPosition)
  45. {
  46. _x = worldPosition._x;
  47. _y = worldPosition._y;
  48. _z = worldPosition._z;
  49. }
  50. public synchronized void setTo(Point3D point)
  51. {
  52. _x = point._x;
  53. _y = point._y;
  54. _z = point._z;
  55. }
  56. @Override
  57. public String toString()
  58. {
  59. return "(" + _x + ", " + _y + ", " + _z + ")";
  60. }
  61. @Override
  62. public int hashCode()
  63. {
  64. return _x ^ _y ^ _z;
  65. }
  66. @Override
  67. public boolean equals(Object o)
  68. {
  69. if (o instanceof Point3D)
  70. {
  71. Point3D point3D = (Point3D) o;
  72. boolean ret = point3D._x == _x && point3D._y == _y && point3D._z == _z;
  73. return ret;
  74. }
  75. return false;
  76. }
  77. public boolean equals(int pX, int pY, int pZ)
  78. {
  79. return _x == pX && _y == pY && _z == pZ;
  80. }
  81. public long distanceSquaredTo(Point3D point)
  82. {
  83. long dx, dy;
  84. dx = _x - point._x;
  85. dy = _y - point._y;
  86. return (dx * dx) + (dy * dy);
  87. }
  88. public static long distanceSquared(Point3D point1, Point3D point2)
  89. {
  90. long dx, dy;
  91. dx = point1._x - point2._x;
  92. dy = point1._y - point2._y;
  93. return (dx * dx) + (dy * dy);
  94. }
  95. public static boolean distanceLessThan(Point3D point1, Point3D point2, double distance)
  96. {
  97. return distanceSquared(point1, point2) < distance * distance;
  98. }
  99. public synchronized int getX()
  100. {
  101. return _x;
  102. }
  103. public synchronized void setX(int pX)
  104. {
  105. _x = pX;
  106. }
  107. public synchronized int getY()
  108. {
  109. return _y;
  110. }
  111. public synchronized void setY(int pY)
  112. {
  113. _y = pY;
  114. }
  115. public synchronized int getZ()
  116. {
  117. return _z;
  118. }
  119. public synchronized void setZ(int pZ)
  120. {
  121. _z = pZ;
  122. }
  123. public synchronized void setXYZ(int pX, int pY, int pZ)
  124. {
  125. _x = pX;
  126. _y = pY;
  127. _z = pZ;
  128. }
  129. }