Skip to content

Commit

Permalink
feat: Introduce concepts for (Regular)Surface (#2646)
Browse files Browse the repository at this point in the history
This helps catching missing `using` methods to make derived classes fully comply with the base `Surface` class. C++ inheritance is strange.

Blocked by:
- #2340
  • Loading branch information
paulgessinger authored Nov 21, 2023
1 parent 3d1dc45 commit e574e8a
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Core/include/Acts/Surfaces/ConeSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "Acts/Surfaces/ConeBounds.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Result.hpp"
#include "Acts/Utilities/detail/RealQuadraticEquation.hpp"

Expand Down Expand Up @@ -278,4 +280,6 @@ class ConeSurface : public RegularSurface {
const Vector3& direction) const;
};

ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, ConeSurface);

} // namespace Acts
4 changes: 4 additions & 0 deletions Core/include/Acts/Surfaces/CylinderSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "Acts/Surfaces/CylinderBounds.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Result.hpp"
#include "Acts/Utilities/detail/RealQuadraticEquation.hpp"

Expand Down Expand Up @@ -285,4 +287,6 @@ class CylinderSurface : public RegularSurface {
const Vector3& direction) const;
};

ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, CylinderSurface);

} // namespace Acts
5 changes: 5 additions & 0 deletions Core/include/Acts/Surfaces/DiscSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "Acts/Surfaces/InfiniteBounds.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Result.hpp"

#include <cmath>
Expand Down Expand Up @@ -328,4 +330,7 @@ class DiscSurface : public RegularSurface {
protected:
std::shared_ptr<const DiscBounds> m_bounds; ///< bounds (shared)
};

ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, DiscSurface);

} // end of namespace Acts
4 changes: 4 additions & 0 deletions Core/include/Acts/Surfaces/PerigeeSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "Acts/Surfaces/InfiniteBounds.hpp"
#include "Acts/Surfaces/LineSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"

#include <cstddef>
#include <iosfwd>
Expand Down Expand Up @@ -91,4 +93,6 @@ class PerigeeSurface : public LineSurface {
std::size_t lseg) const final;
};

ACTS_STATIC_CHECK_CONCEPT(SurfaceConcept, PerigeeSurface);

} // namespace Acts
4 changes: 4 additions & 0 deletions Core/include/Acts/Surfaces/PlaneSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include "Acts/Surfaces/PlanarBounds.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Result.hpp"

#include <cstddef>
Expand Down Expand Up @@ -232,4 +234,6 @@ class PlaneSurface : public RegularSurface {
private:
};

ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, PlaneSurface);

} // end of namespace Acts
4 changes: 4 additions & 0 deletions Core/include/Acts/Surfaces/StrawSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "Acts/Surfaces/LineBounds.hpp"
#include "Acts/Surfaces/LineSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"

#include <cstddef>
#include <memory>
Expand Down Expand Up @@ -108,4 +110,6 @@ inline std::string Acts::StrawSurface::name() const {
return "Acts::StrawSurface";
}

ACTS_STATIC_CHECK_CONCEPT(SurfaceConcept, StrawSurface);

} // namespace Acts
133 changes: 133 additions & 0 deletions Core/include/Acts/Surfaces/SurfaceConcept.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Alignment.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Geometry/DetectorElementBase.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Material/ISurfaceMaterial.hpp"
#include "Acts/Surfaces/BoundaryCheck.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"
#include "Acts/Utilities/Result.hpp"

#if defined(__cpp_concepts)
#include <concepts>

namespace Acts {

template <typename S>
concept SurfaceConcept = requires(S s, const S cs, S s2, const S cs2,
GeometryContext gctx) {
{ cs == s2 } -> std::same_as<bool>;

{ cs.type() } -> std::same_as<Surface::SurfaceType>;
{ cs.transform(gctx) } -> std::same_as<const Transform3&>;
{ cs.center(gctx) } -> std::same_as<Vector3>;
{ cs.normal(gctx, Vector3{}, Vector3{}) } -> std::same_as<Vector3>;
{ cs.bounds() } -> std::convertible_to<const SurfaceBounds&>;
{
cs.associatedDetectorElement()
} -> std::same_as<const DetectorElementBase*>;

{ cs.associatedLayer() } -> std::same_as<const Layer*>;
{ s.associateLayer(std::declval<const Layer&>()) } -> std::same_as<void>;

{ cs.surfaceMaterial() } -> std::same_as<const ISurfaceMaterial*>;
{
cs.surfaceMaterialSharedPtr()
} -> std::same_as<const std::shared_ptr<const ISurfaceMaterial>&>;
{
s.assignSurfaceMaterial(
std::declval<std::shared_ptr<const ISurfaceMaterial>>())
} -> std::same_as<void>;
{
cs.isOnSurface(gctx, Vector3{}, Vector3{},
std::declval<const BoundaryCheck&>())
} -> std::same_as<bool>;
{
cs.insideBounds(Vector2{}, std::declval<const BoundaryCheck&>())
} -> std::same_as<bool>;

{ cs.localToGlobal(gctx, Vector2{}, Vector3{}) } -> std::same_as<Vector3>;

{
cs.globalToLocal(gctx, Vector3{}, Vector3{}, double{5})
} -> std::same_as<Result<Vector2>>;

{
cs.referenceFrame(gctx, Vector3{}, Vector3{})
} -> std::same_as<RotationMatrix3>;

{
cs.boundToFreeJacobian(gctx, BoundVector{})
} -> std::same_as<BoundToFreeMatrix>;

{
cs.boundToFreeJacobian(gctx, BoundVector{})
} -> std::same_as<BoundToFreeMatrix>;

{
cs.freeToBoundJacobian(gctx, FreeVector{})
} -> std::same_as<FreeToBoundMatrix>;

{
cs.freeToPathDerivative(gctx, FreeVector{})
} -> std::same_as<FreeToPathMatrix>;

{ cs.pathCorrection(gctx, Vector3{}, Vector3{}) } -> std::same_as<double>;

{
cs.intersect(gctx, Vector3{}, Vector3{},
std::declval<const BoundaryCheck&>(), std::declval<double>())
} -> std::same_as<SurfaceMultiIntersection>;

{
cs.toStream(gctx, std::declval<std::ostream&>())
} -> std::same_as<std::ostream&>;

{ cs.toString(gctx) } -> std::same_as<std::string>;

{ cs.name() } -> std::same_as<std::string>;

{
cs.polyhedronRepresentation(gctx, std::declval<std::size_t>())
} -> std::same_as<Polyhedron>;

{
cs.alignmentToBoundDerivative(gctx, FreeVector{}, FreeVector{})
} -> std::same_as<AlignmentToBoundMatrix>;

{
cs.alignmentToPathDerivative(gctx, FreeVector{})
} -> std::same_as<AlignmentToPathMatrix>;

{
cs.localCartesianToBoundLocalDerivative(gctx, Vector3{})
} -> std::same_as<ActsMatrix<2, 3>>;
};

template <typename S>
concept RegularSurfaceConcept = SurfaceConcept<S> &&
requires(S s, const S cs, GeometryContext gctx) {
{ cs.normal(gctx, Vector2{}) } -> std::same_as<Vector3>;

{ cs.normal(gctx, Vector3{}) } -> std::same_as<Vector3>;

{
cs.globalToLocal(gctx, Vector3{}, Vector3{}, std::declval<double>())
} -> std::same_as<Result<Vector2>>;

{ cs.localToGlobal(gctx, Vector2{}) } -> std::same_as<Vector3>;
};
} // namespace Acts

#endif
9 changes: 9 additions & 0 deletions Tests/UnitTests/Core/Surfaces/SurfaceStub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "Acts/Surfaces/PlanarBounds.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Intersection.hpp"

namespace Acts {
Expand Down Expand Up @@ -57,13 +59,17 @@ class SurfaceStub : public RegularSurface {
return Vector3(0., 0., 0.);
}

using RegularSurface::localToGlobal;

/// Global to local transformation
Result<Vector2> globalToLocal(const GeometryContext& /*cxt*/,
const Vector3& /*gpos*/,
double /*tolerance*/) const final {
return Result<Vector2>::success(Vector2{20., 20.});
}

using RegularSurface::globalToLocal;

/// Calculation of the path correction for incident
double pathCorrection(const GeometryContext& /*cxt*/, const Vector3& /*gpos*/,
const Vector3& /*gmom*/) const final {
Expand Down Expand Up @@ -115,4 +121,7 @@ class SurfaceStub : public RegularSurface {
/// the bounds of this surface
std::shared_ptr<const PlanarBounds> m_bounds;
};

ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, SurfaceStub);

} // namespace Acts

0 comments on commit e574e8a

Please sign in to comment.