fix some bugs in clip.lua
Add autosnap and many supporting functional utilities