From 1938235d9d277c75bee5e3c6eadb9bf7aa04fb67 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Sun, 24 Nov 2024 10:07:41 +0100 Subject: [PATCH] pr feedback --- .../Material/HomogeneousSurfaceMaterial.hpp | 15 ++++++++++----- .../Material/HomogeneousVolumeMaterial.hpp | 17 +++++++++++------ .../Acts/Material/ISurfaceMaterial.hpp | 1 + Core/include/Acts/Material/Material.hpp | 18 +++++++++++------- Core/include/Acts/Material/MaterialSlab.hpp | 19 ++++++++++++------- .../Material/HomogeneousSurfaceMaterial.cpp | 5 ----- .../Material/HomogeneousVolumeMaterial.cpp | 5 ----- Core/src/Material/Material.cpp | 5 ----- Core/src/Material/MaterialSlab.cpp | 5 ----- .../Core/Material/MaterialSlabTests.cpp | 2 ++ 10 files changed, 47 insertions(+), 45 deletions(-) diff --git a/Core/include/Acts/Material/HomogeneousSurfaceMaterial.hpp b/Core/include/Acts/Material/HomogeneousSurfaceMaterial.hpp index dee99dae093..d3d2c2f6733 100644 --- a/Core/include/Acts/Material/HomogeneousSurfaceMaterial.hpp +++ b/Core/include/Acts/Material/HomogeneousSurfaceMaterial.hpp @@ -58,11 +58,6 @@ class HomogeneousSurfaceMaterial : public ISurfaceMaterial { HomogeneousSurfaceMaterial& operator=(HomogeneousSurfaceMaterial&& hsm) = default; - /// Equality operator - /// - /// @param hsm is the source material - bool operator==(const HomogeneousSurfaceMaterial& hsm) const; - /// Scale operator /// - it is effectively a thickness scaling /// @@ -94,6 +89,16 @@ class HomogeneousSurfaceMaterial : public ISurfaceMaterial { private: /// The five different MaterialSlab MaterialSlab m_fullMaterial; + + /// Check if two materials are exactly equal. + /// @note This is a strict equality check, i.e. the materials must + /// have identical properties. + /// @param other is the material to compare to + /// @return true if the materials are equal + friend constexpr bool operator==(const HomogeneousSurfaceMaterial& lhs, + const HomogeneousSurfaceMaterial& rhs) { + return lhs.m_fullMaterial == rhs.m_fullMaterial; + } }; } // namespace Acts diff --git a/Core/include/Acts/Material/HomogeneousVolumeMaterial.hpp b/Core/include/Acts/Material/HomogeneousVolumeMaterial.hpp index 28226b24bed..5136c2139b5 100644 --- a/Core/include/Acts/Material/HomogeneousVolumeMaterial.hpp +++ b/Core/include/Acts/Material/HomogeneousVolumeMaterial.hpp @@ -46,11 +46,6 @@ class HomogeneousVolumeMaterial : public IVolumeMaterial { HomogeneousVolumeMaterial& operator=(const HomogeneousVolumeMaterial& hvm) = default; - /// Equality operator - /// - /// @param hvm is the source material - bool operator==(const HomogeneousVolumeMaterial& hvm) const; - /// Access to actual material /// /// @param position is the request position for the material call @@ -64,7 +59,17 @@ class HomogeneousVolumeMaterial : public IVolumeMaterial { std::ostream& toStream(std::ostream& sl) const final; private: - Material m_material = Material(); + Material m_material; + + /// Check if two materials are exactly equal. + /// @note This is a strict equality check, i.e. the materials must + /// have identical properties. + /// @param other is the material to compare to + /// @return true if the materials are equal + friend constexpr bool operator==(const HomogeneousVolumeMaterial& lhs, + const HomogeneousVolumeMaterial& rhs) { + return lhs.m_material == rhs.m_material; + } }; } // namespace Acts diff --git a/Core/include/Acts/Material/ISurfaceMaterial.hpp b/Core/include/Acts/Material/ISurfaceMaterial.hpp index 457751a128b..cad6832441a 100644 --- a/Core/include/Acts/Material/ISurfaceMaterial.hpp +++ b/Core/include/Acts/Material/ISurfaceMaterial.hpp @@ -127,6 +127,7 @@ class ISurfaceMaterial { protected: /// the split factor in favour of oppositePre double m_splitFactor{1.}; + /// Use the default mapping type by default MappingType m_mappingType{Acts::MappingType::Default}; }; diff --git a/Core/include/Acts/Material/Material.hpp b/Core/include/Acts/Material/Material.hpp index c1993a2843f..41119d1df37 100644 --- a/Core/include/Acts/Material/Material.hpp +++ b/Core/include/Acts/Material/Material.hpp @@ -81,13 +81,6 @@ class Material { Material& operator=(Material&& mat) = default; Material& operator=(const Material& mat) = default; - /// Check if two materials are exactly equal. - /// @note This is a strict equality check, i.e. the materials must - /// have identical properties. - /// @param mat is the material to compare to - /// @return true if the materials are equal - bool operator==(const Material& mat) const; - /// Check if the material is valid, i.e. it is not vacuum. bool isValid() const { return 0.0f < m_ar; } @@ -117,6 +110,17 @@ class Material { float m_ar = 0.0f; float m_z = 0.0f; float m_molarRho = 0.0f; + + /// Check if two materials are exactly equal. + /// @note This is a strict equality check, i.e. the materials must + /// have identical properties. + /// @param mat is the material to compare to + /// @return true if the materials are equal + friend constexpr bool operator==(const Material& lhs, const Material& rhs) { + return (lhs.m_x0 == rhs.m_x0) && (lhs.m_l0 == rhs.m_l0) && + (lhs.m_ar == rhs.m_ar) && (lhs.m_z == rhs.m_z) && + (lhs.m_molarRho == rhs.m_molarRho); + } }; std::ostream& operator<<(std::ostream& os, const Material& material); diff --git a/Core/include/Acts/Material/MaterialSlab.hpp b/Core/include/Acts/Material/MaterialSlab.hpp index 33fa8e8920e..e94e063e9cc 100644 --- a/Core/include/Acts/Material/MaterialSlab.hpp +++ b/Core/include/Acts/Material/MaterialSlab.hpp @@ -58,13 +58,6 @@ class MaterialSlab { MaterialSlab& operator=(MaterialSlab&&) = default; MaterialSlab& operator=(const MaterialSlab&) = default; - /// Check if two materials are exactly equal. - /// @note This is a strict equality check, i.e. the materials must - /// have identical properties. - /// @param other is the material to compare to - /// @return true if the materials are equal - bool operator==(const MaterialSlab& other) const; - /// Scale the material thickness by the given factor. void scaleThickness(float scale); @@ -85,6 +78,18 @@ class MaterialSlab { float m_thickness = 0.0f; float m_thicknessInX0 = 0.0f; float m_thicknessInL0 = 0.0f; + + /// Check if two materials are exactly equal. + /// @note This is a strict equality check, i.e. the materials must + /// have identical properties. + /// @param other is the material to compare to + /// @return true if the materials are equal + friend constexpr bool operator==(const MaterialSlab& lhs, + const MaterialSlab& rhs) { + // t/X0 and t/L0 are dependent variables and need not be checked + return (lhs.m_material == rhs.m_material) && + (lhs.m_thickness == rhs.m_thickness); + } }; std::ostream& operator<<(std::ostream& os, const MaterialSlab& materialSlab); diff --git a/Core/src/Material/HomogeneousSurfaceMaterial.cpp b/Core/src/Material/HomogeneousSurfaceMaterial.cpp index 7ea0009a299..c3bef1f9de3 100644 --- a/Core/src/Material/HomogeneousSurfaceMaterial.cpp +++ b/Core/src/Material/HomogeneousSurfaceMaterial.cpp @@ -19,11 +19,6 @@ HomogeneousSurfaceMaterial::HomogeneousSurfaceMaterial(const MaterialSlab& full, MappingType mappingType) : ISurfaceMaterial(splitFactor, mappingType), m_fullMaterial(full) {} -bool HomogeneousSurfaceMaterial::operator==( - const HomogeneousSurfaceMaterial& hsm) const { - return m_fullMaterial == hsm.m_fullMaterial; -} - HomogeneousSurfaceMaterial& HomogeneousSurfaceMaterial::scale(double factor) { m_fullMaterial.scaleThickness(factor); return *this; diff --git a/Core/src/Material/HomogeneousVolumeMaterial.cpp b/Core/src/Material/HomogeneousVolumeMaterial.cpp index 47932919885..a5ea578f0ce 100644 --- a/Core/src/Material/HomogeneousVolumeMaterial.cpp +++ b/Core/src/Material/HomogeneousVolumeMaterial.cpp @@ -17,11 +17,6 @@ namespace Acts { HomogeneousVolumeMaterial::HomogeneousVolumeMaterial(const Material& material) : m_material(material) {} -bool HomogeneousVolumeMaterial::operator==( - const HomogeneousVolumeMaterial& hvm) const { - return m_material == hvm.m_material; -} - const Material HomogeneousVolumeMaterial::material( const Vector3& /*position*/) const { return m_material; diff --git a/Core/src/Material/Material.cpp b/Core/src/Material/Material.cpp index 7a4deedb129..29d9502fde9 100644 --- a/Core/src/Material/Material.cpp +++ b/Core/src/Material/Material.cpp @@ -80,11 +80,6 @@ float Material::massDensity() const { return atomicMass * numberDensity; } -bool Material::operator==(const Material& mat) const { - return m_x0 == mat.m_x0 && m_l0 == mat.m_l0 && m_ar == mat.m_ar && - m_z == mat.m_z && m_molarRho == mat.m_molarRho; -} - float Material::meanExcitationEnergy() const { using namespace UnitLiterals; diff --git a/Core/src/Material/MaterialSlab.cpp b/Core/src/Material/MaterialSlab.cpp index 698ee8fe58c..4fad731c6c1 100644 --- a/Core/src/Material/MaterialSlab.cpp +++ b/Core/src/Material/MaterialSlab.cpp @@ -11,7 +11,6 @@ #include "Acts/Material/detail/AverageMaterials.hpp" #include -#include #include #include @@ -33,10 +32,6 @@ MaterialSlab::MaterialSlab(const Material& material, float thickness) } } -bool MaterialSlab::operator==(const MaterialSlab& other) const { - return m_material == other.m_material && m_thickness == other.m_thickness; -} - MaterialSlab MaterialSlab::averageLayers(const MaterialSlab& layerA, const MaterialSlab& layerB) { return detail::combineSlabs(layerA, layerB); diff --git a/Tests/UnitTests/Core/Material/MaterialSlabTests.cpp b/Tests/UnitTests/Core/Material/MaterialSlabTests.cpp index 677277ab060..3dfab084a2b 100644 --- a/Tests/UnitTests/Core/Material/MaterialSlabTests.cpp +++ b/Tests/UnitTests/Core/Material/MaterialSlabTests.cpp @@ -70,6 +70,8 @@ BOOST_AUTO_TEST_CASE(scale_thickness) { Acts::MaterialSlab halfScaled = mat; halfScaled.scaleThickness(0.5); + BOOST_CHECK_NE(mat, halfMat); + BOOST_CHECK_EQUAL(halfMat, halfScaled); CHECK_CLOSE_REL(mat.thicknessInX0(), 2 * halfMat.thicknessInX0(), eps); CHECK_CLOSE_REL(mat.thicknessInL0(), 2 * halfMat.thicknessInL0(), eps); CHECK_CLOSE_REL(mat.thickness() * mat.material().massDensity(),