refactoring: factor out coordinates validity checks
fix #3755: crash when user enters invalid coordinates