> But the value of pi is incorrectly rounded and those double casts are
> unnecessary; in any case we clearly do not need double precision:
>     (unsigned char)(int)(atan2f((x - me->p_x), (me->p_y - y)) / 3.141593 * 128.)

Oops, wrong draft. :-P  That should be:
     (unsigned char)(int)(atan2f(x - me->p_x, me->p_y - y) / 3.141593f * 128.f)

> Fixing this requires rounding rather than truncation.  With C99 and
> IMO clearer layout:
>     (unsigned char) (int) ( roundf( 128.f*atan2f( dx, dy )/3.141593f ) )

And that should be:
     (unsigned char) (int) ( roundf( 128.f*atan2f( x - me->p_x,
                                                   me->p_y - y )/3.141593f ) )

Final note: "0" being due north assumes that the x-axis points east
and the y-axis points south.

Cheers
Michael