# direction_func.h

Go to the documentation of this file.

    00001 /* $Id: direction_func.h 11661 2007-12-18 19:52:14Z rubidium $ */
    00002
    00005 #ifndef DIRECTION_FUNC_H
    00006 #define DIRECTION_FUNC_H
    00007
    00008 #include "direction_type.h"
    00009
    00016 static inline Direction ReverseDir(Direction d)
    00017 {
    00018   return (Direction)(4 ^ d);
    00019 }
    00020
    00021
    00029 static inline DirDiff DirDifference(Direction d0, Direction d1)
    00030 {
    00031   return (DirDiff)((d0 + 8 - d1) % 8);
    00032 }
    00033
    00045 static inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
    00046 {
    00047   return (DirDiff)((d + delta) % 8);
    00048 }
    00049
    00060 static inline Direction ChangeDir(Direction d, DirDiff delta)
    00061 {
    00062   return (Direction)((d + delta) % 8);
    00063 }
    00064
    00065
    00072 static inline DiagDirection ReverseDiagDir(DiagDirection d)
    00073 {
    00074   return (DiagDirection)(2 ^ d);
    00075 }
    00076
    00077
    00088 static inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
    00089 {
    00090   return (DiagDirection)((d + delta) % 4);
    00091 }
    00092
    00103 static inline DiagDirection DirToDiagDir(Direction dir)
    00104 {
    00105   return (DiagDirection)(dir >> 1);
    00106 }
    00107
    00118 static inline Direction DiagDirToDir(DiagDirection dir)
    00119 {
    00120   return (Direction)(dir * 2 + 1);
    00121 }
    00122
    00123
    00132 static inline Axis OtherAxis(Axis a)
    00133 {
    00134   return (Axis)(a ^ 1);
    00135 }
    00136
    00137
    00148 static inline Axis DiagDirToAxis(DiagDirection d)
    00149 {
    00150   return (Axis)(d & 1);
    00151 }
    00152
    00153
    00165 static inline DiagDirection AxisToDiagDir(Axis a)
    00166 {
    00167   return (DiagDirection)(2 - a);
    00168 }
    00169
    00176 static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns)
    00177 {
    00178   return (DiagDirection)(xy * 3 ^ ns * 2);
    00179 }
    00180
    00187 static inline bool IsValidDiagDirection(DiagDirection d)
    00188 {
    00189   return d < DIAGDIR_END;
    00190 }
    00191
    00198 static inline bool IsValidDirection(Direction d)
    00199 {
    00200   return d < DIR_END;
    00201 }
    00202
    00209 static inline bool IsValidAxis(Axis d)
    00210 {
    00211   return d < AXIS_END;
    00212 }
    00213
    00214 #endif /* DIRECTION_H */