Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-31 08:16:45

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Surfaces/RectangleBounds.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 double RectangleBounds::get(BoundValues bValue) const {
0021   switch (bValue) {
0022     case eMinX:
0023       return m_min.x();
0024     case eMinY:
0025       return m_min.y();
0026     case eMaxX:
0027       return m_max.x();
0028     case eMaxY:
0029       return m_max.y();
0030     default:
0031       assert(false && "Invalid BoundValue enum value");
0032       return std::numeric_limits<double>::quiet_NaN();
0033   }
0034 }
0035 
0036 std::vector<double> RectangleBounds::values() const {
0037   return {m_min.x(), m_min.y(), m_max.x(), m_max.y()};
0038 }
0039 
0040 void RectangleBounds::checkConsistency() noexcept(false) {
0041   if (get(eMinX) > get(eMaxX)) {
0042     throw std::invalid_argument("RectangleBounds: invalid local x setup");
0043   }
0044   if (get(eMinY) > get(eMaxY)) {
0045     throw std::invalid_argument("RectangleBounds: invalid local y setup");
0046   }
0047 }
0048 
0049 bool RectangleBounds::inside(const Vector2& lposition) const {
0050   return detail::VerticesHelper::isInsideRectangle(lposition, m_min, m_max);
0051 }
0052 
0053 Vector2 RectangleBounds::closestPoint(const Vector2& lposition,
0054                                       const SquareMatrix2& metric) const {
0055   // If no metric is provided we can use a shortcut for the rectangle
0056   if (metric.isIdentity()) {
0057     return detail::VerticesHelper::computeEuclideanClosestPointOnRectangle(
0058         lposition, m_min, m_max);
0059   }
0060 
0061   // Otherwise we need to compute the closest point on the polygon
0062   std::array<Vector2, 4> vertices = {
0063       {m_min, {m_max[0], m_min[1]}, m_max, {m_min[0], m_max[1]}}};
0064   return detail::VerticesHelper::computeClosestPointOnPolygon(lposition,
0065                                                               vertices, metric);
0066 }
0067 
0068 std::vector<Vector2> RectangleBounds::vertices(unsigned int /*lseg*/) const {
0069   // counter-clockwise starting from bottom-left corner
0070   return {m_min, {m_max.x(), m_min.y()}, m_max, {m_min.x(), m_max.y()}};
0071 }
0072 
0073 const RectangleBounds& RectangleBounds::boundingBox() const {
0074   return (*this);
0075 }
0076 
0077 Vector2 RectangleBounds::center() const {
0078   return 0.5 * (m_min + m_max);
0079 }
0080 
0081 std::ostream& RectangleBounds::toStream(std::ostream& sl) const {
0082   sl << std::setiosflags(std::ios::fixed);
0083   sl << std::setprecision(7);
0084   sl << "Acts::RectangleBounds:  (hlX, hlY) = "
0085      << "(" << 0.5 * (get(eMaxX) - get(eMinX)) << ", "
0086      << 0.5 * (get(eMaxY) - get(eMinY)) << ")";
0087   sl << "\n(lower left, upper right):\n";
0088   sl << min().transpose() << "\n" << max().transpose();
0089   sl << std::setprecision(-1);
0090   return sl;
0091 }
0092 
0093 }  // namespace Acts