# direction_func.h

Go to the documentation of this file.

    00001 /* $Id: direction_func.h 12870 2008-04-24 13:05:51Z smatz $ */
    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
    00181 static inline Direction AxisToDirection(Axis a)
    00182 {
    00183   return (Direction)(5 - 2 * a);
    00184 }
    00185
    00192 static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns)
    00193 {
    00194   return (DiagDirection)(xy * 3 ^ ns * 2);
    00195 }
    00196
    00203 static inline bool IsValidDiagDirection(DiagDirection d)
    00204 {
    00205   return d < DIAGDIR_END;
    00206 }
    00207
    00214 static inline bool IsValidDirection(Direction d)
    00215 {
    00216   return d < DIR_END;
    00217 }
    00218
    00225 static inline bool IsValidAxis(Axis d)
    00226 {
    00227   return d < AXIS_END;
    00228 }
    00229
    00230 #endif /* DIRECTION_H */