Warning, file /include/corecel/math/Turn.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <cmath>
0011
0012 #include "corecel/Types.hh"
0013
0014 #include "Algorithms.hh"
0015 #include "Quantity.hh"
0016
0017 namespace celeritas
0018 {
0019
0020
0021 struct TwoPi
0022 {
0023 static real_type value() { return 2 * static_cast<real_type>(m_pi); }
0024
0025 static char const* label() { return "tr"; }
0026 };
0027
0028
0029
0030 struct HalfPi
0031 {
0032 static real_type value() { return static_cast<real_type>(m_pi / 2); }
0033
0034 static char const* label() { return "qtr"; }
0035 };
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 using Turn = Quantity<TwoPi, real_type>;
0046
0047
0048
0049 using QuarterTurn = Quantity<HalfPi, int>;
0050
0051
0052
0053
0054 CELER_FORCEINLINE_FUNCTION real_type sin(Turn r)
0055 {
0056 return sinpi(r.value() * 2);
0057 }
0058
0059 CELER_FORCEINLINE_FUNCTION real_type cos(Turn r)
0060 {
0061 return cospi(r.value() * 2);
0062 }
0063
0064 CELER_FORCEINLINE_FUNCTION void sincos(Turn r, real_type* sinv, real_type* cosv)
0065 {
0066 return sincospi(r.value() * 2, sinv, cosv);
0067 }
0068
0069 CELER_FORCEINLINE_FUNCTION int cos(QuarterTurn r)
0070 {
0071 constexpr int cosval[] = {1, 0, -1, 0};
0072 return cosval[std::abs(r.value()) % 4];
0073 }
0074
0075 CELER_FORCEINLINE_FUNCTION int sin(QuarterTurn r)
0076 {
0077
0078 return cos(QuarterTurn{r.value() - 1});
0079 }
0080
0081 CELER_FORCEINLINE_FUNCTION void sincos(QuarterTurn r, int* sinv, int* cosv)
0082 {
0083 *sinv = sin(r);
0084 *cosv = cos(r);
0085 }
0086
0087
0088
0089 }