Say, you have a single block, you would dock in the angle you are currently closer to
\"a +45 -(a+45)%90\" | for a ={0, 40, 310, 350, 360}, results are {0, 0, 270, 360, 360} -> this formula should be ok.
or \"a +PI/4 -(a +PI/4)%(PI/2)\" if you prefer \"rad\" over \"deg\"
Or you could have a...