Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:17:12

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file orange/surf/SoftSurfaceEqual.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <algorithm>
0011 
0012 #include "corecel/cont/Range.hh"
0013 #include "corecel/math/SoftEqual.hh"
0014 #include "orange/OrangeTypes.hh"
0015 
0016 #include "SurfaceFwd.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Compare two surfaces for exact equality.
0023  *
0024  * Only for exact equality should the local surface inserter return an existing
0025  * ID. Otherwise we could have a small gap between surfaces.
0026  */
0027 struct ExactSurfaceEqual
0028 {
0029     template<class S>
0030     inline bool operator()(S const& a, S const& b) const;
0031 };
0032 
0033 //---------------------------------------------------------------------------//
0034 /*!
0035  * Compare two surfaces for soft equality.
0036  */
0037 class SoftSurfaceEqual
0038 {
0039   public:
0040     // Construct with tolerance
0041     explicit inline SoftSurfaceEqual(Tolerance<> const& tol);
0042 
0043     //! Construct with relative tolerance only
0044     explicit SoftSurfaceEqual(real_type rel)
0045         : SoftSurfaceEqual{Tolerance<>::from_relative(rel)}
0046     {
0047     }
0048 
0049     //! Construct with default tolerance
0050     SoftSurfaceEqual() : SoftSurfaceEqual{Tolerance<>::from_default()} {}
0051 
0052     //// SURFACE FUNCTIONS ////
0053 
0054     template<Axis T>
0055     bool operator()(PlaneAligned<T> const&, PlaneAligned<T> const&) const;
0056 
0057     template<Axis T>
0058     bool operator()(CylCentered<T> const&, CylCentered<T> const&) const;
0059 
0060     bool operator()(SphereCentered const&, SphereCentered const&) const;
0061 
0062     template<Axis T>
0063     bool operator()(CylAligned<T> const&, CylAligned<T> const&) const;
0064 
0065     bool operator()(Plane const&, Plane const&) const;
0066 
0067     bool operator()(Sphere const&, Sphere const&) const;
0068 
0069     template<Axis T>
0070     bool operator()(ConeAligned<T> const&, ConeAligned<T> const&) const;
0071 
0072     bool operator()(SimpleQuadric const&, SimpleQuadric const&) const;
0073 
0074     bool operator()(GeneralQuadric const&, GeneralQuadric const&) const;
0075 
0076     bool operator()(Involute const&, Involute const&) const;
0077 
0078   private:
0079     SoftEqual<> soft_eq_;
0080 
0081     bool soft_eq_sq(real_type a, real_type b) const;
0082     bool soft_eq_distance(Real3 const& a, Real3 const& b) const;
0083 };
0084 
0085 //---------------------------------------------------------------------------//
0086 // INLINE DEFINITIONS
0087 //---------------------------------------------------------------------------//
0088 /*!
0089  * Construct with tolerance.
0090  */
0091 SoftSurfaceEqual::SoftSurfaceEqual(Tolerance<> const& tol)
0092     : soft_eq_{tol.rel, tol.abs}
0093 {
0094     CELER_EXPECT(tol);
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Compare exact equality for two surfaces.
0100  */
0101 template<class S>
0102 bool ExactSurfaceEqual::operator()(S const& a, S const& b) const
0103 {
0104     auto const& data_a = a.data();
0105     auto const& data_b = b.data();
0106     static_assert(std::is_same_v<decltype(data_a), decltype(data_b)>);
0107     auto r = range(data_a.size());
0108     return std::all_of(
0109         r.begin(), r.end(), [&](auto i) { return data_a[i] == data_b[i]; });
0110 }
0111 
0112 //---------------------------------------------------------------------------//
0113 }  // namespace celeritas