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