|
@@ -19,139 +19,104 @@
|
|
package com.l2jserver.gameserver.util;
|
|
package com.l2jserver.gameserver.util;
|
|
|
|
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
+
|
|
|
|
+import com.l2jserver.gameserver.model.Location;
|
|
|
|
+import com.l2jserver.gameserver.model.interfaces.IPositionable;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This class ...
|
|
|
|
- * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
|
|
|
|
|
|
+ * @author Unknown, UnAfraid
|
|
*/
|
|
*/
|
|
-public class Point3D implements Serializable
|
|
|
|
|
|
+public class Point3D implements Serializable, IPositionable
|
|
{
|
|
{
|
|
- /**
|
|
|
|
- * Comment for <code>serialVersionUID</code>
|
|
|
|
- */
|
|
|
|
private static final long serialVersionUID = 4638345252031872576L;
|
|
private static final long serialVersionUID = 4638345252031872576L;
|
|
|
|
|
|
- private volatile int _x, _y, _z;
|
|
|
|
-
|
|
|
|
- public Point3D(int pX, int pY, int pZ)
|
|
|
|
- {
|
|
|
|
- _x = pX;
|
|
|
|
- _y = pY;
|
|
|
|
- _z = pZ;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Point3D(int pX, int pY)
|
|
|
|
- {
|
|
|
|
- _x = pX;
|
|
|
|
- _y = pY;
|
|
|
|
- _z = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ private final AtomicInteger _x = new AtomicInteger();
|
|
|
|
+ private final AtomicInteger _y = new AtomicInteger();
|
|
|
|
+ private final AtomicInteger _z = new AtomicInteger();
|
|
|
|
|
|
- /**
|
|
|
|
- * @param worldPosition
|
|
|
|
- */
|
|
|
|
- public Point3D(Point3D worldPosition)
|
|
|
|
|
|
+ public Point3D(int x, int y, int z)
|
|
{
|
|
{
|
|
- _x = worldPosition._x;
|
|
|
|
- _y = worldPosition._y;
|
|
|
|
- _z = worldPosition._z;
|
|
|
|
|
|
+ _x.set(x);
|
|
|
|
+ _y.set(y);
|
|
|
|
+ _z.set(z);
|
|
}
|
|
}
|
|
|
|
|
|
- public synchronized void setTo(Point3D point)
|
|
|
|
|
|
+ public boolean equals(int x, int y, int z)
|
|
{
|
|
{
|
|
- _x = point._x;
|
|
|
|
- _y = point._y;
|
|
|
|
- _z = point._z;
|
|
|
|
|
|
+ return (getX() == x) && (getY() == y) && (getZ() == z);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String toString()
|
|
|
|
|
|
+ public int getX()
|
|
{
|
|
{
|
|
- return "(" + _x + ", " + _y + ", " + _z + ")";
|
|
|
|
|
|
+ return _x.get();
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public int hashCode()
|
|
|
|
|
|
+ public void setX(int x)
|
|
{
|
|
{
|
|
- return _x ^ _y ^ _z;
|
|
|
|
|
|
+ _x.set(x);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean equals(Object o)
|
|
|
|
- {
|
|
|
|
- if (this == o)
|
|
|
|
- {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- if (o instanceof Point3D)
|
|
|
|
- {
|
|
|
|
- Point3D point3D = (Point3D) o;
|
|
|
|
- boolean ret = (point3D._x == _x) && (point3D._y == _y) && (point3D._z == _z);
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean equals(int pX, int pY, int pZ)
|
|
|
|
- {
|
|
|
|
- return (_x == pX) && (_y == pY) && (_z == pZ);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public long distanceSquaredTo(Point3D point)
|
|
|
|
- {
|
|
|
|
- long dx, dy;
|
|
|
|
- dx = _x - point._x;
|
|
|
|
- dy = _y - point._y;
|
|
|
|
- return (dx * dx) + (dy * dy);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static long distanceSquared(Point3D point1, Point3D point2)
|
|
|
|
|
|
+ public int getY()
|
|
{
|
|
{
|
|
- long dx, dy;
|
|
|
|
- dx = point1._x - point2._x;
|
|
|
|
- dy = point1._y - point2._y;
|
|
|
|
- return (dx * dx) + (dy * dy);
|
|
|
|
|
|
+ return _y.get();
|
|
}
|
|
}
|
|
|
|
|
|
- public static boolean distanceLessThan(Point3D point1, Point3D point2, double distance)
|
|
|
|
|
|
+ public void setY(int y)
|
|
{
|
|
{
|
|
- return distanceSquared(point1, point2) < (distance * distance);
|
|
|
|
|
|
+ _y.set(y);
|
|
}
|
|
}
|
|
|
|
|
|
- public int getX()
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public int getZ()
|
|
{
|
|
{
|
|
- return _x;
|
|
|
|
|
|
+ return _z.get();
|
|
}
|
|
}
|
|
|
|
|
|
- public synchronized void setX(int pX)
|
|
|
|
|
|
+ public void setZ(int z)
|
|
{
|
|
{
|
|
- _x = pX;
|
|
|
|
|
|
+ _z.set(z);
|
|
}
|
|
}
|
|
|
|
|
|
- public int getY()
|
|
|
|
|
|
+ public void setXYZ(int x, int y, int z)
|
|
{
|
|
{
|
|
- return _y;
|
|
|
|
|
|
+ _x.set(x);
|
|
|
|
+ _y.set(y);
|
|
|
|
+ _z.set(z);
|
|
}
|
|
}
|
|
|
|
|
|
- public synchronized void setY(int pY)
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Location getLocation()
|
|
{
|
|
{
|
|
- _y = pY;
|
|
|
|
|
|
+ return new Location(getX(), getY(), getZ());
|
|
}
|
|
}
|
|
|
|
|
|
- public int getZ()
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public String toString()
|
|
{
|
|
{
|
|
- return _z;
|
|
|
|
|
|
+ return "(" + _x + ", " + _y + ", " + _z + ")";
|
|
}
|
|
}
|
|
|
|
|
|
- public synchronized void setZ(int pZ)
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode()
|
|
{
|
|
{
|
|
- _z = pZ;
|
|
|
|
|
|
+ return getX() ^ getY() ^ getZ();
|
|
}
|
|
}
|
|
|
|
|
|
- public synchronized void setXYZ(int pX, int pY, int pZ)
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean equals(Object o)
|
|
{
|
|
{
|
|
- _x = pX;
|
|
|
|
- _y = pY;
|
|
|
|
- _z = pZ;
|
|
|
|
|
|
+ if (this == o)
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (o instanceof Point3D)
|
|
|
|
+ {
|
|
|
|
+ final Point3D point3D = (Point3D) o;
|
|
|
|
+ return (point3D.getX() == getX()) && (point3D.getY() == getY()) && (point3D.getZ() == getZ());
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
}
|
|
}
|