Not sharing yet ;)
The algorithm is short yet takes into account direction / speed without needing to calculate direction / speed.
Copyright in progress