Deciding turn direction for avoidance maneuver

tldr: the title. How does it calculate the optimal turn?

Hey all,
When ArduPilot calculates a destination for an avoidance maneuver, how does it decide the best way to turn to actually get there, whether that be to double back and cross over it’s track, or to turn the other way. Basically, how does it decide which side, left or right to start the turn? I’d expect it would be some kind of series of conditional statements that would take into account the position of the closest approach of the obstacle, the absolute distance it would take for the vehicle to reach the destination depending on if it turned left or right, and the physical limits of the vehicle turn radius. But I can’t find where in the code this is actually decided. My hunch is it would be near where plane.guided_WP_loc.offset is called, because that tells ArduPilot the destination. Any and all help is deeply appreciated!
Thanks!