Yeah, quite nasty...seems so easy at the beginning. Another strange thing occurs
if the two directions are exactly opposite to each other. In that case no average
angle can be defined properly.
I guess the basic task is not to average the angles but to determine the vectorial sum of
the direction vectors
V1 = (cos theta1, sin theta1)
V2 = (cos theta2, sin theta2)
(theta1 and theta2 are the getDirs of the units):
V=V1+V2=(cos theta1+cos theta2, sin theta1+sin theta2)
and determine its angle, which corresponds to the average angle. With that approach you
have the length of the summed vector as additional information:
Suppose you have 10 units. If the summed vector has then the length 10, you know that all
units have exactly the same direction. If it is zero they walk around like crazy.
I hope there is some easier solution than this, though