File indexing completed on 2025-01-19 09:23:35
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/BoundaryCheck.hpp"
0013 #include "Acts/Surfaces/PlanarBounds.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015
0016 #include <array>
0017 #include <cassert>
0018 #include <iosfwd>
0019 #include <limits>
0020 #include <stdexcept>
0021 #include <vector>
0022
0023 namespace Acts {
0024
0025
0026
0027
0028
0029
0030
0031
0032 class RectangleBounds : public PlanarBounds {
0033 public:
0034 enum BoundValues : int {
0035 eMinX = 0,
0036 eMinY = 1,
0037 eMaxX = 2,
0038 eMaxY = 3,
0039 eSize = 4
0040 };
0041
0042 RectangleBounds() = delete;
0043
0044
0045
0046
0047
0048 RectangleBounds(double halfX, double halfY) noexcept(false)
0049 : m_min({-halfX, -halfY}), m_max({halfX, halfY}) {
0050 checkConsistency();
0051 }
0052
0053
0054
0055
0056 RectangleBounds(const std::array<double, eSize>& values) noexcept(false)
0057 : m_min({values[eMinX], values[eMinY]}),
0058 m_max({values[eMaxX], values[eMaxY]}) {
0059 checkConsistency();
0060 }
0061
0062
0063
0064
0065
0066 RectangleBounds(const Vector2& min, const Vector2& max) noexcept(false)
0067 : m_min(min), m_max(max) {
0068 checkConsistency();
0069 }
0070
0071 ~RectangleBounds() override = default;
0072
0073 BoundsType type() const final;
0074
0075 std::vector<double> values() const final;
0076
0077
0078
0079
0080
0081
0082
0083
0084 bool inside(const Vector2& lposition,
0085 const BoundaryCheck& bcheck) const final;
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
0096
0097
0098 const RectangleBounds& boundingBox() const final;
0099
0100
0101
0102
0103 std::ostream& toStream(std::ostream& sl) const final;
0104
0105
0106
0107 double get(BoundValues bValue) const;
0108
0109
0110 double halfLengthX() const;
0111
0112
0113 double halfLengthY() const;
0114
0115
0116
0117 const Vector2& min() const;
0118
0119
0120
0121 const Vector2& max() const;
0122
0123 private:
0124 Vector2 m_min;
0125 Vector2 m_max;
0126
0127
0128
0129 void checkConsistency() noexcept(false);
0130 };
0131
0132 inline SurfaceBounds::BoundsType RectangleBounds::type() const {
0133 return SurfaceBounds::eRectangle;
0134 }
0135
0136 inline const Vector2& RectangleBounds::min() const {
0137 return m_min;
0138 }
0139
0140 inline const Vector2& RectangleBounds::max() const {
0141 return m_max;
0142 }
0143
0144 inline double RectangleBounds::halfLengthX() const {
0145 return 0.5 * (m_max.x() - m_min.x());
0146 }
0147
0148 inline double RectangleBounds::halfLengthY() const {
0149 return 0.5 * (m_max.y() - m_min.y());
0150 }
0151
0152 inline std::vector<double> RectangleBounds::values() const {
0153 return {m_min.x(), m_min.y(), m_max.x(), m_max.y()};
0154 }
0155
0156 inline double RectangleBounds::get(BoundValues bValue) const {
0157 switch (bValue) {
0158 case eMinX:
0159 return m_min.x();
0160 case eMinY:
0161 return m_min.y();
0162 case eMaxX:
0163 return m_max.x();
0164 case eMaxY:
0165 return m_max.y();
0166 default:
0167 assert(false && "Invalid BoundValue enum value");
0168 return std::numeric_limits<double>::quiet_NaN();
0169 }
0170 }
0171
0172 inline void RectangleBounds::checkConsistency() noexcept(false) {
0173 if (get(eMinX) > get(eMaxX)) {
0174 throw std::invalid_argument("RectangleBounds: invalid local x setup");
0175 }
0176 if (get(eMinY) > get(eMaxY)) {
0177 throw std::invalid_argument("RectangleBounds: invalid local y setup");
0178 }
0179 }
0180
0181 }