--- ../patch/_airport_entry/direction_func.h 2015-07-12 22:30:37 +0200 +++ src/direction_func.h 2015-07-12 22:47:13 +0200 @@ -59,6 +59,17 @@ return (Direction)(4 ^ d); } +/** + * Return the reverse of a direction difference + * + * @param d The direction difference to get the reverse from + * @return The reverse direction difference + */ +static inline DirDiff ReverseDirDiff(DirDiff d) +{ + /* Cast to uint so compiler can use bitmask. Result can never be negative. */ + return (DirDiff)((uint)(DIRDIFF_SAME - d) % 8); +} /** * Calculate the difference between two directions @@ -124,6 +135,18 @@ } /** + * Return the reverse of a DiagDirDiff difference + * + * @param d The direction difference to get the reverse from + * @return The reverse direction difference + */ +static inline DiagDirDiff ReverseDiagDirDiff(DiagDirDiff d) +{ + /* Cast to uint so compiler can use bitmask. Result can never be negative. */ + return (DiagDirDiff)((uint)(DIAGDIRDIFF_SAME - d) % 4); +} + +/** * Calculate the difference between two DiagDirection values * * @param d0 The first direction as the base @@ -139,6 +162,23 @@ } /** + * Applies two DiagDirDiff differences together + * + * This function adds two differences together and returns the resulting + * difference. So adding two DIAGDIRDIFF_REVERSE together results in the + * DIAGDIRDIFF_SAME difference. + * + * @param d The first difference + * @param delta The second difference to add on + * @return The resulting difference + */ +static inline DiagDirDiff ChangeDiagDirDiff(DiagDirDiff d, DiagDirDiff delta) +{ + /* Cast to uint so compiler can use bitmask. Result can never be negative. */ + return (DiagDirDiff)((uint)(d + delta) % 4); +} + +/** * Applies a difference on a DiagDirection * * This function applies a difference on a DiagDirection and returns