ROBAST: Development of a ROOT-based ray-tracing library for cosmic-ray telescopes and its applications in the Cherenkov Telescope Array