Edge condition, mouse position calculation