File indexing completed on 2026-07-28 08:19:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Surfaces/RectangleBounds.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0013 #include "Acts/Utilities/detail/OstreamStateGuard.hpp"
0014
0015 #include <cassert>
0016 #include <iomanip>
0017 #include <iostream>
0018 #include <stdexcept>
0019
0020 namespace Acts {
0021
0022 double RectangleBounds::get(BoundValues bValue) const {
0023 switch (bValue) {
0024 case eMinX:
0025 return m_min.x();
0026 case eMinY:
0027 return m_min.y();
0028 case eMaxX:
0029 return m_max.x();
0030 case eMaxY:
0031 return m_max.y();
0032 default:
0033 assert(false && "Invalid BoundValue enum value");
0034 return std::numeric_limits<double>::quiet_NaN();
0035 }
0036 }
0037
0038 std::vector<double> RectangleBounds::values() const {
0039 return {m_min.x(), m_min.y(), m_max.x(), m_max.y()};
0040 }
0041
0042 void RectangleBounds::checkConsistency() noexcept(false) {
0043 if (get(eMinX) > get(eMaxX)) {
0044 throw std::invalid_argument("RectangleBounds: invalid local x setup");
0045 }
0046 if (get(eMinY) > get(eMaxY)) {
0047 throw std::invalid_argument("RectangleBounds: invalid local y setup");
0048 }
0049 }
0050
0051 bool RectangleBounds::inside(const Vector2& lposition) const {
0052 return detail::VerticesHelper::isInsideRectangle(lposition, m_min, m_max);
0053 }
0054
0055 Vector2 RectangleBounds::closestPoint(const Vector2& lposition,
0056 const SquareMatrix2& metric) const {
0057
0058 if (metric.isIdentity()) {
0059 return detail::VerticesHelper::computeEuclideanClosestPointOnRectangle(
0060 lposition, m_min, m_max);
0061 }
0062
0063
0064 std::array<Vector2, 4> vertices = {
0065 {m_min, {m_max[0], m_min[1]}, m_max, {m_min[0], m_max[1]}}};
0066 return detail::VerticesHelper::computeClosestPointOnPolygon(lposition,
0067 vertices, metric);
0068 }
0069
0070 std::vector<Vector2> RectangleBounds::vertices(unsigned int ) const {
0071
0072 return {m_min, {m_max.x(), m_min.y()}, m_max, {m_min.x(), m_max.y()}};
0073 }
0074
0075 const RectangleBounds& RectangleBounds::boundingBox() const {
0076 return (*this);
0077 }
0078
0079 Vector2 RectangleBounds::center() const {
0080 return 0.5 * (m_min + m_max);
0081 }
0082
0083 std::ostream& RectangleBounds::toStream(std::ostream& sl) const {
0084 detail::OstreamStateGuard guard{sl};
0085 sl << std::fixed << std::setprecision(7);
0086 sl << "Acts::RectangleBounds: (hlX, hlY) = "
0087 << "(" << 0.5 * (get(eMaxX) - get(eMinX)) << ", "
0088 << 0.5 * (get(eMaxY) - get(eMinY)) << ")";
0089 sl << "\n(lower left, upper right):\n";
0090 sl << min().transpose() << "\n" << max().transpose();
0091 return sl;
0092 }
0093
0094 }