@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(this instanceof PrecisePoint)) return false; PrecisePoint other = (PrecisePoint) obj; if (Double.compare(this.getX(), other.getX()) != 0) return false; if (Double.compare(this.getY(), other.getY()) != 0) return false; return true; }
/** * Indicates whether or not the given object is equal to the rounded values of this {@link * PrecisePoint}. * * @param obj the reference object with which to compare * @param tolerance the tolerance of the difference between the points * @return true if this object is the same as the obj argument; false otherwise */ public boolean equalsNoPrecision(Object obj, double tolerance) { if (obj instanceof PrecisePoint) { PrecisePoint point = (PrecisePoint) obj; long diffX = Math.round(this.getX() - point.getX()); long diffY = Math.round(this.getY() - point.getY()); return (diffX >= -tolerance && diffX <= tolerance && diffY >= -tolerance && diffY <= tolerance); } return super.equals(obj); }
/** * Creates a copy of the given {@link PrecisePoint}. * * @param point the point to be copied */ public PrecisePoint(PrecisePoint point) { this.x = point.getX(); this.y = point.getY(); }