The change in c9c31fcbc2 missed a number of cases. This reverts back to the system as it existed before 2be352b9f9 but using the revised method of determining A-B-C distance and avoiding resizing the arrays (cherry picked from commit 675a5a6e7b)
c9c31fcbc2
2be352b9f9
675a5a6e7b