Ray Tracing in a Weekend in Ruby. I've made some decisions when porting it. Disagree with me if you like. That sounds like your problem. https://raytracing.github.io/books/RayTracingInOneWeekend.html