http://rosettacode.org/wiki/Ray-casting_algorithm