As the code comment says that normalize_poly is used to find the right ordering for the vertices, it should fix the ref vertices while looping the p's ordering to calculate the minimum distance. However, the code seems to loop the ref's and p's ordering simultaneously, so the square distance may not work properly.
`
for (size_t start = 0; start < 4; start ++) {
size_t j = start;
std::int64_t d = (
sqr(ref.poly[(j + 0) % 4].X - p.poly[(j + 0) % 4].X) #always 0-0, missing 0-1, 0-2, 0-3
As the code comment says that normalize_poly is used to find the right ordering for the vertices, it should fix the ref vertices while looping the p's ordering to calculate the minimum distance. However, the code seems to loop the ref's and p's ordering simultaneously, so the square distance may not work properly. ` for (size_t start = 0; start < 4; start ++) { size_t j = start; std::int64_t d = ( sqr(ref.poly[(j + 0) % 4].X - p.poly[(j + 0) % 4].X) #always 0-0, missing 0-1, 0-2, 0-3
d = ( sqr(ref.poly[(j + 0) % 4].X - p.poly[(j + 3) % 4].X) #0-3 or 0-1