Make cleaner setCoords and geometry code

First draft.
Just to keep track of it.
(sorry i use this repo as a dashboard)

A third copy of this function is used in setCoords() but i have to check it better.