| package net.lightstone.model; |
| |
| public final class Position { |
| |
| public static final int GRANULARITY = 32; |
| |
| public static final Position ZERO = new Position(0, 0, 0); |
| |
| private final double x, y, z; |
| |
| public Position(double x, double y, double z) { |
| this.x = x; |
| this.y = y; |
| this.z = z; |
| } |
| |
| public double getX() { |
| return x; |
| } |
| |
| public double getY() { |
| return y; |
| } |
| |
| public double getZ() { |
| return z; |
| } |
| |
| public int getAbsX() { |
| return (int) (x * GRANULARITY); |
| } |
| |
| public int getAbsY() { |
| return (int) (y * GRANULARITY); |
| } |
| |
| public int getAbsZ() { |
| return (int) (z * GRANULARITY); |
| } |
| |
| @Override |
| public int hashCode() { |
| final int prime = 31; |
| int result = 1; |
| long temp; |
| temp = Double.doubleToLongBits(x); |
| result = prime * result + (int) (temp ^ (temp >>> 32)); |
| temp = Double.doubleToLongBits(y); |
| result = prime * result + (int) (temp ^ (temp >>> 32)); |
| temp = Double.doubleToLongBits(z); |
| result = prime * result + (int) (temp ^ (temp >>> 32)); |
| return result; |
| } |
| |
| @Override |
| public boolean equals(Object obj) { |
| if (this == obj) |
| return true; |
| if (obj == null) |
| return false; |
| if (getClass() != obj.getClass()) |
| return false; |
| Position other = (Position) obj; |
| if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) |
| return false; |
| if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) |
| return false; |
| if (Double.doubleToLongBits(z) != Double.doubleToLongBits(other.z)) |
| return false; |
| return true; |
| } |
| |
| } |