The interpolation functions you pointed me to would have been godd for the actual interpolation. Unfortunately, I need to calculate `weight` too, so I need the ugly branching anyway. If I then start calling into the interpolation code at the same time, that would do the branching twice, so I think I'm going to leave the code as it is.