How can I find on which side of an EdgeCollider2D a collision takes place?

Hello, I have a terrain GameObject with an EdgeCollider2D and a Character GameObject with a Random Collider.
I want to find on which side of the EdgeCollider2D the Collision is happening on whenever OnCollisionEnter2D is called.
I wrote these 3 functions to kinda do this, but they are too slow (there is a ~3-frame lag spike whenever my GameObject collides with Terrain) and sometimes imprecise.

Is there any faster and more precise way for me to do this?

Edit: I have a small typo on the code at Pastebin, the first function is not supposed to have the ‘Alt’ at the end…

Example image:
alt text

Does your terrain tend to continue in one direction as in your example?

If so, you could reduce the number you check through by whether the x position of the contact point is greater or less than the x position of the middle point. Then find whether it’s greater or less than the middle point of that half of the points. Then whether it’s … and so on.

This should give you mostly logarithmic time complexity.

Though, if your terrain overlaps in the x position at all, you may need to intentionally include more points in the final check loop.