Here, we might be observing the red shape as being farther away, but it is really closer than the yellow one. Just at the moment they overlap, it looks like they are equidistant, but they continue to move together, allowing the red shape to occlude the yellow shape.

Occlusion was used since Paleolithic times, and was known to the Egyptians as well. In fact, in early cave paintings, occlusion was the first clue that ancient artists knew how to convery depth.