Why does this in-place matrix rotation corrupt values on the inner layer?

WaffleFries
Fri, 03 Apr 2026 22:38:34 +0000

Before:1 2 3 4 5 6 7 8 9After a 90° clockwise rotation:7 4 1 8 5 2 9 6 3A good debugging signal is to label a 4x4 with unique values and watch one inner-layer cycle, like 6 -> 10 -> 11 -> 7 -> 6; if that loop breaks or repeats early, the layer bounds are wrong, not the swap order.