/** * gets the distance between this repulsion force's wall and the input mass * * @param mass - mass to find the distance to * @return dist - distance to mass */ public double getDistance(Mass mass) { double dist = 0; if (mySide == TOP_WALL) { dist = mass.getY(); } else if (mySide == RIGHT_WALL) { dist = mass.getX(); } else if (mySide == BOTTOM_WALL) { dist = mass.getY() - myHeight; } else if (mySide == LEFT_WALL) { dist = mass.getX() - myWidth; } return dist; }
/** Convenience method. */ public double distance(Mass other) { // this is a little awkward, so hide it return new Location(getX(), getY()).distance(new Location(other.getX(), other.getY())); }