File indexing completed on 2025-01-18 09:11:03
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0012 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0013
0014 #include <span>
0015
0016 namespace Acts::detail {
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 inline bool insideAlignedBox(const Vector2& lowerLeft,
0028 const Vector2& upperRight,
0029 const BoundaryTolerance& tolerance,
0030 const Vector2& point,
0031 const std::optional<SquareMatrix2>& jacobianOpt) {
0032 using enum BoundaryTolerance::ToleranceMode;
0033
0034 if (tolerance.isInfinite()) {
0035 return true;
0036 }
0037
0038 BoundaryTolerance::ToleranceMode mode = tolerance.toleranceMode();
0039 bool insideRectangle =
0040 detail::VerticesHelper::isInsideRectangle(point, lowerLeft, upperRight);
0041
0042 if (mode == None) {
0043 return insideRectangle;
0044 }
0045
0046 if (mode == Extend && insideRectangle) {
0047 return true;
0048 }
0049
0050 Vector2 closestPoint;
0051
0052 if (!tolerance.hasMetric(jacobianOpt.has_value())) {
0053 closestPoint =
0054 detail::VerticesHelper::computeEuclideanClosestPointOnRectangle(
0055 point, lowerLeft, upperRight);
0056 } else {
0057
0058
0059
0060 std::array<Vector2, 4> vertices = {{lowerLeft,
0061 {upperRight[0], lowerLeft[1]},
0062 upperRight,
0063 {lowerLeft[0], upperRight[1]}}};
0064
0065 SquareMatrix2 metric = tolerance.getMetric(jacobianOpt);
0066
0067 closestPoint = detail::VerticesHelper::computeClosestPointOnPolygon(
0068 point, vertices, metric);
0069 }
0070
0071 Vector2 distance = closestPoint - point;
0072
0073 if (mode == Extend) {
0074 return tolerance.isTolerated(distance, jacobianOpt);
0075 } else {
0076 return tolerance.isTolerated(distance, jacobianOpt) && insideRectangle;
0077 }
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 inline bool insidePolygon(std::span<const Vector2> vertices,
0089 const BoundaryTolerance& tolerance,
0090 const Vector2& point,
0091 const std::optional<SquareMatrix2>& jacobianOpt) {
0092 using enum BoundaryTolerance::ToleranceMode;
0093 if (tolerance.isInfinite()) {
0094
0095 return true;
0096 }
0097
0098 BoundaryTolerance::ToleranceMode mode = tolerance.toleranceMode();
0099 bool insidePolygon = detail::VerticesHelper::isInsidePolygon(point, vertices);
0100
0101 if (mode == None) {
0102
0103
0104
0105
0106
0107
0108 return insidePolygon;
0109 }
0110
0111 if (mode == Extend && insidePolygon) {
0112 return true;
0113 }
0114
0115
0116
0117
0118
0119
0120 SquareMatrix2 metric = tolerance.getMetric(jacobianOpt);
0121
0122
0123
0124 auto closestPoint = detail::VerticesHelper::computeClosestPointOnPolygon(
0125 point, vertices, metric);
0126
0127 Vector2 distance = closestPoint - point;
0128
0129 if (mode == Extend) {
0130 return tolerance.isTolerated(distance, jacobianOpt);
0131 } else {
0132
0133 return tolerance.isTolerated(-distance, jacobianOpt) && insidePolygon;
0134 }
0135 }
0136
0137 }