Refactor coordinate calculation when resizing