Most challenging function written for my ray casting program in C.