class GeometryTools {

    public static IAtom getClosestAtom(int xPosition, int yPosition, IAtomContainer atomCon) {
        IAtom closestAtom = null;
        IAtom currentAtom;
        double smallestMouseDistance = -1;
        double mouseDistance;
        double atomX;
        double atomY;
        for (int i = 0; i < atomCon.getAtomCount(); i++) {
            currentAtom = atomCon.getAtom(i);
            atomX = currentAtom.getPoint2d().x;
            atomY = currentAtom.getPoint2d().y;
            mouseDistance = Math.sqrt(Math.pow(atomX - xPosition, 2) + Math.pow(atomY - yPosition, 2));
            if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {
                smallestMouseDistance = mouseDistance;
                closestAtom = currentAtom;
            }
        }
        return closestAtom;
    }

}