implementing 1d visibility graph