I have no idea how macOS does it, but the obvious thing to try is to leave the relative positioning undefined until the first time the user tries to move the mouse off one screen, and assume they're aiming for the other screen.
It would probably make sense to constrain this to horizontal movements, so that taking advantage of Fitts' Law to hit the menu bar or the Dock (at the bottom by default) wouldn't produce a false positive signal about display positioning when stacked display setups are less common than side by side.
For me the macOS Display management experience is absolute dreadful. I had the same issues as the author's and I even had to pay actual money for a third party application (BetterDisplay) to fix some of the issues.
The most infurienting one for me is that I can't disable the internal MacBook display when I am connected to an external monitor without closing the lid. Why you may ask? Because I want to keep using the TouchID. However this is impossible in macOS without an external app.