Wow, this is really impressive. The terrain is huge!
Edit: It was interesting glancing through your code and noticing comments like ’is it inside the triangle?’ and ’getting height by by bilinear such-and-such’. Fun to see someone else’s answers to the same things I’ve been dealing with my game, which was mostly inspired by seeing the terrain function and thinking it was cool :)