How to check and turn a corner while wall hugging?

While I’m trying to figure out the direction (version control exists), how would the logic for figuring out what corner to turn work? Would that require line tracing in 8 directions, but I don’t think that would be necessary because all corners would just be 90°. Or would that somehow require a check by ‘sweeping’ from 0-90° (like making a custom trace shape, just checked, you can’t do that), if there’s a hit, then there’s a corner and you can turn.