Просто в теории, тяжело на деле
Determine if a point is inside a polygon. Author gives some solution, but I remember seeing Freya's tweet about using the winding number method, which I find to be better and cover more edge cases
https://habr.com/en/post/645345/
Solution: https://twitter.com/FreyaHolmer/status/1232826293902888960?s=20
#windingnumber
Post #1606
58