\doxysection{Grid\+Direction.\+hpp}
\hypertarget{GridDirection_8hpp_source}{}\label{GridDirection_8hpp_source}\index{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/GridDirection.hpp@{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/GridDirection.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#ifndef\ GYM\_PCB\_GRIDDIRECTION\_H}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#define\ GYM\_PCB\_GRIDDIRECTION\_H}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{keyword}{class\ }GridDirection}
\DoxyCodeLine{00006\ \{}
\DoxyCodeLine{00007\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00008\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ uint\ FirstVertical\ =\ 8;}
\DoxyCodeLine{00009\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ uint\ Count\ =\ 10;}
\DoxyCodeLine{00010\ \ \ \ \ \textcolor{keyword}{constexpr}\ GridDirection(uint8\_t\ i)\ :\ id(i)\ \{\ assert(\textcolor{keywordtype}{id}\ <=\ 0xa);\ \}}
\DoxyCodeLine{00011\ \ \ \ \ \textcolor{keyword}{constexpr}\ GridDirection()\ \{\ \}}
\DoxyCodeLine{00012\ \ \ \ \ GridDirection(\textcolor{keyword}{const}\ \mbox{\hyperlink{classIVector__3}{IVector\_3}}\&);}
\DoxyCodeLine{00013\ \ \ \ \ uint\ n()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ id;\ \}}
\DoxyCodeLine{00014\ \ \ \ \ \textcolor{keyword}{constexpr}\ uint32\_t\ mask()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ (1\ <<\ \textcolor{keywordtype}{id});\ \}}
\DoxyCodeLine{00015\ \ \ \ \ \textcolor{keywordtype}{bool}\ \_isDiagonal()\textcolor{keyword}{\ const\ }\{\ assert(!isVertical());\ \textcolor{keywordflow}{return}\ \textcolor{keywordtype}{id}\ \&\ 0x1;\ \}}
\DoxyCodeLine{00016\ \ \ \ \ \textcolor{keywordtype}{bool}\ isDiagonal()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ (\textcolor{keywordtype}{id}\ \&\ 0x1)\ \&\&\ (\textcolor{keywordtype}{id}\ <\ 8);\ \}}
\DoxyCodeLine{00017\ \ \ \ \ \textcolor{keywordtype}{bool}\ isZero()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \textcolor{keywordtype}{id}\ ==\ 0xa;\ \}}
\DoxyCodeLine{00018\ \ \ \ \ \textcolor{keywordtype}{bool}\ isVertical()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ (\textcolor{keywordtype}{id}\ ==\ 8)\ ||\ (\textcolor{keywordtype}{id}\ ==\ 9);\ \}}
\DoxyCodeLine{00019\ \ \ \ \ \textcolor{keywordtype}{bool}\ is2D()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \textcolor{keywordtype}{id}\ <\ 8;\ \}}
\DoxyCodeLine{00020\ \ \ \ \ \textcolor{keywordtype}{bool}\ operator==(\textcolor{keyword}{const}\ GridDirection\ \&d)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \textcolor{keywordtype}{id}\ ==\ d.id;\ \}}
\DoxyCodeLine{00021\ \ \ \ \ GridDirection\&\ operator++()\ \{\ \textcolor{keywordtype}{id}\ +=\ 1;\ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};\ \}}
\DoxyCodeLine{00022\ \ \ \ \ GridDirection\&\ operator=(\textcolor{keyword}{const}\ GridDirection\ \&d)\ \{\ \textcolor{keywordtype}{id}\ =\ d.id;\ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};\ \}}
\DoxyCodeLine{00023\ \ \ \ \ \textcolor{keywordtype}{int}\ dx()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ dXYZ[id][0];\ \}}
\DoxyCodeLine{00024\ \ \ \ \ \textcolor{keywordtype}{int}\ dy()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ dXYZ[id][1];\ \}}
\DoxyCodeLine{00025\ \ \ \ \ \textcolor{keywordtype}{int}\ dz()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ dXYZ[id][2];\ \}}
\DoxyCodeLine{00026\ \ \ \ \ \mbox{\hyperlink{classIVector__3}{IVector\_3}}\ ivec3()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classIVector__3}{IVector\_3}}(dXYZ[\textcolor{keywordtype}{id}][0],\ dXYZ[\textcolor{keywordtype}{id}][1],\ dXYZ[\textcolor{keywordtype}{id}][2]);\ \}}
\DoxyCodeLine{00027\ \ \ \ \ Vector\_2\ vec2()\textcolor{keyword}{\ const\ }\{\ assert(\textcolor{keywordtype}{id}\ <=\ 7);\ \textcolor{keywordflow}{return}\ sVec[id];\ \}}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordtype}{int}\ deg()\textcolor{keyword}{\ const\ }\{\ assert(\textcolor{keywordtype}{id}\ <=\ 7);\ \textcolor{keywordflow}{return}\ 90\ -\/\ \textcolor{keywordtype}{id}\ *\ 45\ +\ (\textcolor{keywordtype}{id}\ >=\ 3\ ?\ 0\ :\ 360);\ \}}
\DoxyCodeLine{00029\ \ \ \ \ GridDirection\ opposite()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ GridDirection(sOpposites[\textcolor{keywordtype}{id}]);\ \}}
\DoxyCodeLine{00030\ \ \ \ \ GridDirection\ rotatedCcw45(uint\ n\ =\ 1)\textcolor{keyword}{\ const\ }\{\ assert(\textcolor{keywordtype}{id}\ <\ 8);\ \textcolor{keywordflow}{return}\ GridDirection((\textcolor{keywordtype}{id}\ -\/\ n)\ \&\ 0x7);\ \}}
\DoxyCodeLine{00031\ \ \ \ \ GridDirection\ rotatedCw45(uint\ n\ =\ 1)\textcolor{keyword}{\ const\ }\{\ assert(\textcolor{keywordtype}{id}\ <\ 8);\ \textcolor{keywordflow}{return}\ GridDirection((\textcolor{keywordtype}{id}\ +\ n)\ \&\ 0x7);\ \}}
\DoxyCodeLine{00032\ \ \ \ \ GridDirection\ rotatedCcw(\textcolor{keywordtype}{int}\ degrees)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00033\ \ \ \ \ uint8\_t\ get45DegreeStepsBetween(\textcolor{keyword}{const}\ GridDirection\ \&d)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ sStrings[std::min(\textcolor{keywordtype}{id},\ uint8\_t(10))];\ \}}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keyword}{static}\ GridDirection\ Degrees(\textcolor{keywordtype}{int});\ \textcolor{comment}{//\ 0°\ ==\ R,\ ccw}}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keyword}{static}\ GridDirection\ fromSigns(\textcolor{keyword}{const}\ Vector\_2\&,\ Real\ zeroThreshold\ =\ 0x1.0p-\/10);}
\DoxyCodeLine{00037\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ begin()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(0);\ \}}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ hend()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(8);\ \}}
\DoxyCodeLine{00039\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ vend()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(10);\ \}}
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ U()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(0);\ \}}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ UR()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(1);\ \}}
\DoxyCodeLine{00042\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ R()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(2);\ \}}
\DoxyCodeLine{00043\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ DR()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(3);\ \}}
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ D()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(4);\ \}}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ DL()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(5);\ \}}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ L()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(6);\ \}}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ UL()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(7);\ \}}
\DoxyCodeLine{00048\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ A()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(8);\ \}}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ V()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(9);\ \}}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{static}\ GridDirection\ Z()\ \{\ \textcolor{keywordflow}{return}\ GridDirection(10);\ \}}
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ dXYZ[11][3];}
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ Vector\_2\ sVec[11];}
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ uint8\_t\ sOpposites[11];}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *sStrings[11];}
\DoxyCodeLine{00055\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00056\ \ \ \ \ uint8\_t\ id;}
\DoxyCodeLine{00057\ \};}
\DoxyCodeLine{00058\ \textcolor{keyword}{inline}\ uint8\_t\ GridDirection::get45DegreeStepsBetween(\textcolor{keyword}{const}\ \mbox{\hyperlink{classGridDirection}{GridDirection}}\ \&d)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00059\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keywordflow}{if}\ ((\textcolor{keywordtype}{id}\ |\ d.id)\ \&\ 0x8)}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00062\ \ \ \ \ \textcolor{keyword}{auto}\ n\ =\ std::abs(\textcolor{keywordtype}{id}\ -\/\ d.id);}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keywordflow}{return}\ (n\ >\ 4)\ ?\ (uint8\_t(8)\ -\/\ n)\ :\ n;}
\DoxyCodeLine{00064\ \}}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ GYM\_PCB\_GRIDDIRECTION\_H}}
\DoxyCodeLine{00067\ }

\end{DoxyCode}
