Skip to content

Commit 6333ad6

Browse files
authored
chore: Use cloneable ptr to default copy ctor && assignment (acts-project#5119)
Simplify surface copy constructor && assignment operator
1 parent 768427e commit 6333ad6

File tree

2 files changed

+5
-33
lines changed

2 files changed

+5
-33
lines changed

Core/include/Acts/Surfaces/Surface.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Acts/Surfaces/BoundaryTolerance.hpp"
2020
#include "Acts/Surfaces/SurfaceBounds.hpp"
2121
#include "Acts/Surfaces/SurfacePlacementBase.hpp"
22+
#include "Acts/Utilities/CloneablePtr.hpp"
2223
#include "Acts/Utilities/Intersection.hpp"
2324
#include "Acts/Utilities/Result.hpp"
2425
#include "Acts/Visualization/ViewConfig.hpp"
@@ -89,7 +90,7 @@ class Surface : public virtual GeometryObject,
8990
/// to detector element and layer
9091
///
9192
/// @param other Source surface for copy.
92-
Surface(const Surface& other) noexcept;
93+
Surface(const Surface& other) noexcept = default;
9394

9495
/// Constructor from SurfacePlacement: Element proxy
9596
///
@@ -153,7 +154,7 @@ class Surface : public virtual GeometryObject,
153154
///
154155
/// @param other Source surface for the assignment
155156
/// @return Reference to this surface after assignment
156-
Surface& operator=(const Surface& other);
157+
Surface& operator=(const Surface& other) noexcept = default;
157158

158159
/// Comparison (equality) operator
159160
/// The strategy for comparison is
@@ -563,7 +564,7 @@ class Surface : public virtual GeometryObject,
563564

564565
/// Transform3 definition that positions
565566
/// (translation, rotation) the surface in global space
566-
std::unique_ptr<const Transform3> m_transform{};
567+
CloneablePtr<const Transform3> m_transform{};
567568

568569
private:
569570
/// Pointer to the a SurfacePlacement

Core/src/Surfaces/Surface.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ Surface::Surface(const Transform3& transform)
2626
Surface::Surface(const SurfacePlacementBase& placement) noexcept
2727
: GeometryObject(), m_placement(&placement) {}
2828

29-
Surface::Surface(const Surface& other) noexcept
30-
: GeometryObject(other),
31-
std::enable_shared_from_this<Surface>(),
32-
m_placement(other.m_placement),
33-
m_surfaceMaterial(other.m_surfaceMaterial) {
34-
if (other.m_transform) {
35-
m_transform = std::make_unique<Transform3>(*other.m_transform);
36-
}
37-
}
38-
3929
Surface::Surface(const GeometryContext& gctx, const Surface& other,
4030
const Transform3& shift) noexcept
4131
: GeometryObject(),
@@ -158,23 +148,6 @@ std::shared_ptr<const Surface> Surface::getSharedPtr() const {
158148
return shared_from_this();
159149
}
160150

161-
Surface& Surface::operator=(const Surface& other) {
162-
if (&other != this) {
163-
GeometryObject::operator=(other);
164-
// detector element, identifier & layer association are unique
165-
if (other.m_transform) {
166-
m_transform = std::make_unique<Transform3>(*other.m_transform);
167-
} else {
168-
m_transform.reset();
169-
}
170-
m_associatedLayer = other.m_associatedLayer;
171-
m_surfaceMaterial = other.m_surfaceMaterial;
172-
m_placement = other.m_placement;
173-
m_isSensitive = other.m_isSensitive;
174-
}
175-
return *this;
176-
}
177-
178151
bool Surface::operator==(const Surface& other) const {
179152
// (a) fast exit for pointer comparison
180153
if (&other == this) {
@@ -241,9 +214,7 @@ std::string Surface::toString(const GeometryContext& gctx) const {
241214
}
242215

243216
Vector3 Surface::center(const GeometryContext& gctx) const {
244-
// fast access via transform matrix (and not translation())
245-
auto tMatrix = localToGlobalTransform(gctx).matrix();
246-
return Vector3(tMatrix(0, 3), tMatrix(1, 3), tMatrix(2, 3));
217+
return localToGlobalTransform(gctx).translation();
247218
}
248219

249220
const Transform3& Surface::transform(const GeometryContext& gctx) const {

0 commit comments

Comments
 (0)