Does normalize_poly in lanms have a bug in calculating the square distance?
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 + sqr(ref.poly[(j + 0) % 4].Y - p.poly[(j + 0) % 4].Y) + sqr(ref.poly[(j + 1) % 4].X - p.poly[(j + 1) % 4].X) + sqr(ref.poly[(j + 1) % 4].Y - p.poly[(j + 1) % 4].Y) + sqr(ref.poly[(j + 2) % 4].X - p.poly[(j + 2) % 4].X) + sqr(ref.poly[(j + 2) % 4].Y - p.poly[(j + 2) % 4].Y) + sqr(ref.poly[(j + 3) % 4].X - p.poly[(j + 3) % 4].X) + sqr(ref.poly[(j + 3) % 4].Y - p.poly[(j + 3) % 4].Y) ); if (d < min_d) { min_d = d; best_start = start; best_order = 0; }
d = ( sqr(ref.poly[(j + 0) % 4].X - p.poly[(j + 3) % 4].X) #0-3 or 0-1 + sqr(ref.poly[(j + 0) % 4].Y - p.poly[(j + 3) % 4].Y) + sqr(ref.poly[(j + 1) % 4].X - p.poly[(j + 2) % 4].X) + sqr(ref.poly[(j + 1) % 4].Y - p.poly[(j + 2) % 4].Y) + sqr(ref.poly[(j + 2) % 4].X - p.poly[(j + 1) % 4].X) + sqr(ref.poly[(j + 2) % 4].Y - p.poly[(j + 1) % 4].Y) + sqr(ref.poly[(j + 3) % 4].X - p.poly[(j + 0) % 4].X) + sqr(ref.poly[(j + 3) % 4].Y - p.poly[(j + 0) % 4].Y) ); if (d < min_d) { min_d = d; best_start = start; best_order = 1; } } ` Am I right?
I agree with you. Do you have a new fixed .whl ? @minizon