Implement GLB algorithm. (Issue #2263)

r? @brson

These algorithms can be improved but this is more correct than what we have now (and I think good enough for me to land my other patches that rely on these algorithms being correct).  All tests pass, at least locally.