File indexing completed on 2025-01-30 10:17:13
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <algorithm>
0011
0012 #include "corecel/cont/Span.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/ArrayOperators.hh"
0015 #include "orange/OrangeTypes.hh"
0016
0017 namespace celeritas
0018 {
0019
0020
0021
0022
0023
0024
0025
0026 class Translation
0027 {
0028 public:
0029
0030
0031 using StorageSpan = Span<real_type const, 3>;
0032
0033
0034
0035 static CELER_CONSTEXPR_FUNCTION TransformType transform_type()
0036 {
0037 return TransformType::translation;
0038 }
0039
0040 public:
0041
0042 explicit CELER_FUNCTION Translation() : tra_{0, 0, 0} {}
0043
0044
0045 explicit CELER_FUNCTION Translation(Real3 const& trans) : tra_(trans) {}
0046
0047
0048 explicit inline CELER_FUNCTION Translation(StorageSpan s);
0049
0050
0051
0052
0053 CELER_FORCEINLINE_FUNCTION Real3 const& translation() const
0054 {
0055 return tra_;
0056 }
0057
0058
0059 CELER_FUNCTION StorageSpan data() const { return {&tra_[0], 3}; }
0060
0061
0062
0063
0064 inline CELER_FUNCTION Real3 transform_up(Real3 const& pos) const;
0065
0066
0067 inline CELER_FUNCTION Real3 transform_down(Real3 const& parent_pos) const;
0068
0069
0070 inline CELER_FUNCTION Real3 const& rotate_up(Real3 const& d) const;
0071
0072
0073 inline CELER_FUNCTION Real3 const& rotate_down(Real3 const& d) const;
0074
0075
0076 Translation calc_inverse() const { return Translation{negate(tra_)}; }
0077
0078 private:
0079 Real3 tra_;
0080 };
0081
0082
0083
0084
0085
0086
0087 inline bool operator==(Translation const& a, Translation const& b)
0088 {
0089 auto a_data = a.data();
0090 return std::equal(a_data.begin(), a_data.end(), b.data().begin());
0091 }
0092
0093 inline bool operator!=(Translation const& a, Translation const& b)
0094 {
0095 return !(a == b);
0096 }
0097
0098
0099
0100
0101
0102
0103
0104
0105 CELER_FUNCTION Translation::Translation(StorageSpan s) : tra_{s[0], s[1], s[2]}
0106 {
0107 }
0108
0109
0110
0111
0112
0113 CELER_FORCEINLINE_FUNCTION Real3 Translation::transform_up(Real3 const& pos) const
0114 {
0115 return pos + tra_;
0116 }
0117
0118
0119
0120
0121
0122 CELER_FORCEINLINE_FUNCTION Real3
0123 Translation::transform_down(Real3 const& parent_pos) const
0124 {
0125 return parent_pos - tra_;
0126 }
0127
0128
0129
0130
0131
0132 CELER_FORCEINLINE_FUNCTION Real3 const&
0133 Translation::rotate_up(Real3 const& d) const
0134 {
0135 return d;
0136 }
0137
0138
0139
0140
0141
0142 CELER_FORCEINLINE_FUNCTION Real3 const&
0143 Translation::rotate_down(Real3 const& d) const
0144 {
0145 return d;
0146 }
0147
0148
0149 }