Improve SnapToTick algorithm, code optimizations