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