maybe i didnt try enough with your example but it seems its not possible to use the terrain object as a platform, or am i wrong?
nonetheless i really like what youre done there! and i have many ideas to use this canvas/destination out solution for something else, great job!
btw i dont know if it helps but i learned last week at university that algorythms that have nested "for loops" take very much time, but unfortunately im not very good at optimizing them (yet) so i cant give advice on how to make yours different, but i can ask my colleague and lecturer at friday how to improve your algorythm, were doing nothing else then estimating how long algyrythms take and if its possible to optimize them in this class. are you familiar with "divide and conquer" method ? maybe you could use it or something likewise to optimize your algorythm.