File indexing completed on 2025-09-16 08:13:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Surfaces/DiamondBounds.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0013
0014 #include <iomanip>
0015 #include <iostream>
0016 #include <stdexcept>
0017
0018 namespace Acts {
0019
0020 std::vector<double> DiamondBounds::values() const {
0021 return {m_values.begin(), m_values.end()};
0022 }
0023
0024 void DiamondBounds::checkConsistency() noexcept(false) {
0025 if (std::ranges::any_of(m_values, [](auto v) { return v <= 0.; })) {
0026 throw std::invalid_argument("DiamondBounds: negative half length.");
0027 }
0028 if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) ||
0029 get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
0030 throw std::invalid_argument("DiamondBounds: not a diamond shape.");
0031 }
0032 }
0033
0034 bool DiamondBounds::inside(const Vector2& lposition) const {
0035
0036
0037 double x1 = get(DiamondBounds::eHalfLengthXnegY);
0038 double y1 = get(DiamondBounds::eHalfLengthYneg);
0039 double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0040 double y2 = 0.;
0041 double x3 = get(DiamondBounds::eHalfLengthXposY);
0042 double y3 = get(DiamondBounds::eHalfLengthYpos);
0043 std::array<Vector2, 6> vertices{
0044 {{-x1, -y1}, {x1, -y1}, {x2, y2}, {x3, y3}, {-x3, y3}, {-x2, y2}}};
0045 return detail::VerticesHelper::isInsidePolygon(lposition, vertices);
0046 }
0047
0048 Vector2 DiamondBounds::closestPoint(const Vector2& lposition,
0049 const SquareMatrix2& metric) const {
0050
0051
0052 double x1 = get(DiamondBounds::eHalfLengthXnegY);
0053 double y1 = get(DiamondBounds::eHalfLengthYneg);
0054 double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0055 double y2 = 0.;
0056 double x3 = get(DiamondBounds::eHalfLengthXposY);
0057 double y3 = get(DiamondBounds::eHalfLengthYpos);
0058 Vector2 vertices[] = {{-x1, -y1}, {x1, -y1}, {x2, y2},
0059 {x3, y3}, {-x3, y3}, {-x2, y2}};
0060 return detail::VerticesHelper::computeClosestPointOnPolygon(lposition,
0061 vertices, metric);
0062 }
0063
0064 std::vector<Vector2> DiamondBounds::vertices(
0065 unsigned int ) const {
0066
0067
0068 double x1 = get(DiamondBounds::eHalfLengthXnegY);
0069 double y1 = get(DiamondBounds::eHalfLengthYneg);
0070 double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0071 double y2 = 0.;
0072 double x3 = get(DiamondBounds::eHalfLengthXposY);
0073 double y3 = get(DiamondBounds::eHalfLengthYpos);
0074 return {{-x1, -y1}, {x1, -y1}, {x2, y2}, {x3, y3}, {-x3, y3}, {-x2, y2}};
0075 }
0076
0077 const RectangleBounds& DiamondBounds::boundingBox() const {
0078 return m_boundingBox;
0079 }
0080
0081 Vector2 DiamondBounds::center() const {
0082
0083
0084 return Vector2::Zero();
0085 }
0086
0087 std::ostream& DiamondBounds::toStream(std::ostream& sl) const {
0088 sl << std::setiosflags(std::ios::fixed);
0089 sl << std::setprecision(7);
0090 sl << "Acts::DiamondBounds: (halfXatYneg, halfXatYzero, halfXatYpos, "
0091 "halfYneg, halfYpos) = ";
0092 sl << "(" << get(DiamondBounds::eHalfLengthXnegY) << ", "
0093 << get(DiamondBounds::eHalfLengthXzeroY) << ", "
0094 << get(DiamondBounds::eHalfLengthXposY) << ", "
0095 << get(DiamondBounds::eHalfLengthYneg) << ", "
0096 << get(DiamondBounds::eHalfLengthYpos) << ")";
0097 sl << std::setprecision(-1);
0098 return sl;
0099 }
0100
0101 }