File indexing completed on 2025-01-30 10:17:12
0001
0002
0003
0004
0005
0006
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
0023
0024
0025
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
0036
0037 class SoftSurfaceEqual
0038 {
0039 public:
0040
0041 explicit inline SoftSurfaceEqual(Tolerance<> const& tol);
0042
0043
0044 explicit SoftSurfaceEqual(real_type rel)
0045 : SoftSurfaceEqual{Tolerance<>::from_relative(rel)}
0046 {
0047 }
0048
0049
0050 SoftSurfaceEqual() : SoftSurfaceEqual{Tolerance<>::from_default()} {}
0051
0052
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
0087
0088
0089
0090
0091 SoftSurfaceEqual::SoftSurfaceEqual(Tolerance<> const& tol)
0092 : soft_eq_{tol.rel, tol.abs}
0093 {
0094 CELER_EXPECT(tol);
0095 }
0096
0097
0098
0099
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 }