Bendy ruler cross fence when avoidanc obstacle

I make inclusion fence, near the fence border there is an obstacle, when the rover detected the obstacle, the rover will go back first then find new route, use bendy ruler for the obstacle avoidance.
In this case its back can cross the border of the fence.

I found my rover did it.
How to prevent the rover cross the border of the fence.

Or when the GPS position is over the fence, force it go back by forward or backward