Implement snapToGrid method