I am trying to adopt Moore-Neighbor contour tracing algorithm in my JavaScript project and at the moment I'm reading this tutorial on contour tracing: http://www.imageprocessingplace.com/downloads_V3/root_downloads/tutorials/contour_tracing_Abeer_George_Ghuneim/square.html
But I have a problem with understanding Jacob's stopping criterion. Tutorial explains this criterion as
Stop after entering the start pixel a second time in the same manner you entered it initially
As I understand, that means that if we entered the start pixel S at the first time with a certain absolute direction (for example, UP if we are searching the start pixel from the bottom left corner), we have to stop tracing after reentering the start pixel with the same absolute direction (UP, as the first time).
That sounds very clear, but I found some cases where this condition will never be fulfilled. One of these cases is shown on this picture: Jacobs stopping criterion issue
As you can see, the start pixel (marked as S) was initially entered with the UP direction (purple arrow), but the second and all the other times it will be entered with the LEFT direction (red arrow). So, Jacob's stopping criterion (enter the start pixel with the same direction as the first time) will never fulfill.
I guess, I've just misunderstood this part of the tutorial... I'll be really happy if you explain to me where I am wrong.