Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-17 10:21:52

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/transform/Translation.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <algorithm>
0010 
0011 #include "corecel/cont/LdgSpan.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  * Apply a translation (no rotation).
0021  *
0022  * The input translation is specified by translating the daughter's coordinate
0023  * into the parent.
0024  */
0025 class Translation
0026 {
0027   public:
0028     //@{
0029     //! \name Type aliases
0030     using StorageSpan = LdgSpan<real_type const, 3>;
0031     //@}
0032 
0033     //! Transform type identifier
0034     static CELER_CONSTEXPR_FUNCTION TransformType transform_type()
0035     {
0036         return TransformType::translation;
0037     }
0038 
0039   public:
0040     //! Construct with an identity translation
0041     explicit CELER_FUNCTION Translation() : tra_{0, 0, 0} {}
0042 
0043     //! Construct with the translation vector
0044     explicit CELER_FUNCTION Translation(Real3 const& trans) : tra_(trans) {}
0045 
0046     // Construct inline from storage
0047     explicit inline CELER_FUNCTION Translation(StorageSpan s);
0048 
0049     //// ACCESSORS ////
0050 
0051     //! Translation vector
0052     CELER_FORCEINLINE_FUNCTION Real3 const& translation() const
0053     {
0054         return tra_;
0055     }
0056 
0057     //! Get a view to the data for type-deleted storage
0058     CELER_FUNCTION StorageSpan data() const { return {&tra_[0], 3}; }
0059 
0060     //// CALCULATION ////
0061 
0062     // Transform from daughter to parent
0063     inline CELER_FUNCTION Real3 transform_up(Real3 const& pos) const;
0064 
0065     // Transform from parent to daughter
0066     inline CELER_FUNCTION Real3 transform_down(Real3 const& parent_pos) const;
0067 
0068     // Rotate from daughter to parent (identity)
0069     inline CELER_FUNCTION Real3 const& rotate_up(Real3 const& d) const;
0070 
0071     // Rotate from parent to daughter (identity)
0072     inline CELER_FUNCTION Real3 const& rotate_down(Real3 const& d) const;
0073 
0074     //! Calculate the inverse during preprocessing
0075     Translation calc_inverse() const { return Translation{negate(tra_)}; }
0076 
0077     //!@{
0078     //! Host-only comparators
0079     friend bool operator==(Translation const& a, Translation const& b)
0080     {
0081         auto a_data = a.data();
0082         return std::equal(a_data.begin(), a_data.end(), b.data().begin());
0083     }
0084     friend bool operator!=(Translation const& a, Translation const& b)
0085     {
0086         return !(a == b);
0087     }
0088     //!@}
0089 
0090   private:
0091     Real3 tra_;
0092 };
0093 
0094 //---------------------------------------------------------------------------//
0095 // INLINE DEFINITIONS
0096 //---------------------------------------------------------------------------//
0097 /*!
0098  * Construct inline from storage.
0099  */
0100 CELER_FUNCTION Translation::Translation(StorageSpan s) : tra_{s[0], s[1], s[2]}
0101 {
0102 }
0103 
0104 //---------------------------------------------------------------------------//
0105 /*!
0106  * Transform from daughter to parent.
0107  */
0108 CELER_FORCEINLINE_FUNCTION Real3 Translation::transform_up(
0109     Real3 const& pos) const
0110 {
0111     return pos + tra_;
0112 }
0113 
0114 //---------------------------------------------------------------------------//
0115 /*!
0116  * Transform from parent to daughter.
0117  */
0118 CELER_FORCEINLINE_FUNCTION Real3 Translation::transform_down(
0119     Real3 const& parent_pos) const
0120 {
0121     return parent_pos - tra_;
0122 }
0123 
0124 //---------------------------------------------------------------------------//
0125 /*!
0126  * Rotate from daughter to parent (identity).
0127  */
0128 CELER_FORCEINLINE_FUNCTION Real3 const& Translation::rotate_up(
0129     Real3 const& d) const
0130 {
0131     return d;
0132 }
0133 
0134 //---------------------------------------------------------------------------//
0135 /*!
0136  * Rotate from parent to daughter (identity).
0137  */
0138 CELER_FORCEINLINE_FUNCTION Real3 const& Translation::rotate_down(
0139     Real3 const& d) const
0140 {
0141     return d;
0142 }
0143 
0144 //---------------------------------------------------------------------------//
0145 }  // namespace celeritas