added snapToNearest method