Skip to content

Commit

Permalink
add tolerance calculation including negative for rect, poly and annulus
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Dec 19, 2024
1 parent fe43453 commit b4817ab
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 215 deletions.
14 changes: 12 additions & 2 deletions Core/include/Acts/Surfaces/BoundaryTolerance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class BoundaryTolerance {

AbsoluteBound() = default;
AbsoluteBound(double tolerance0_, double tolerance1_)
: tolerance0(tolerance0_), tolerance1(tolerance1_) {}
: tolerance0(tolerance0_), tolerance1(tolerance1_) {
if (tolerance0 < 0 || tolerance1 < 0) {
throw std::invalid_argument(
"AbsoluteBound: Tolerance must be non-negative");
}
}
};

/// Absolute tolerance in Cartesian coordinates
Expand All @@ -77,7 +82,12 @@ class BoundaryTolerance {

AbsoluteCartesian() = default;
AbsoluteCartesian(double tolerance0_, double tolerance1_)
: tolerance0(tolerance0_), tolerance1(tolerance1_) {}
: tolerance0(tolerance0_), tolerance1(tolerance1_) {
if (tolerance0 < 0 || tolerance1 < 0) {
throw std::invalid_argument(
"AbsoluteCartesian: Tolerance must be non-negative");
}
}
};

/// Absolute tolerance in Euclidean distance
Expand Down
28 changes: 17 additions & 11 deletions Core/include/Acts/Surfaces/detail/BoundaryCheckHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@ inline bool insideAlignedBox(const Vector2& lowerLeft,
point, vertices, metric);
}

std::cout << "closestPoint: " << closestPoint.transpose() << std::endl;
std::cout << "point: " << point.transpose() << std::endl;
Vector2 distance = closestPoint - point;
std::cout << "distance: " << distance.transpose() << std::endl;

if (mode == Extend) {
return tolerance.isTolerated(distance, jacobianOpt);
} else {
return tolerance.isTolerated(-distance, jacobianOpt) && insideRectangle;
return tolerance.isTolerated(distance, jacobianOpt) && insideRectangle;
}
}

Expand All @@ -93,23 +90,27 @@ inline bool insidePolygon(std::span<const Vector2> vertices,
const BoundaryTolerance& tolerance,
const Vector2& point,
const std::optional<SquareMatrix2>& jacobianOpt) {
using enum BoundaryTolerance::ToleranceMode;
if (tolerance.isInfinite()) {
// The null boundary check always succeeds
return true;
}

if (detail::VerticesHelper::isInsidePolygon(point, vertices)) {
// If the point falls inside the polygon, the check always succeeds
return true;
}
BoundaryTolerance::ToleranceMode mode = tolerance.toleranceMode();
bool insidePolygon = detail::VerticesHelper::isInsidePolygon(point, vertices);

if (tolerance.toleranceMode() == BoundaryTolerance::ToleranceMode::None) {
if (mode == None) {
// If the point falls inside the polygon, the check always succeeds
// Outside of the polygon, since we've eliminated the case of an absence of
// check above, we know we'll always fail if the tolerance is zero.
//
// This allows us to avoid the expensive computeClosestPointOnPolygon
// computation in this simple case.
return false;
return insidePolygon;
}

if (mode == Extend && insidePolygon) {
return true;
}

// TODO: When tolerance is not 0, we could also avoid this computation in
Expand All @@ -126,7 +127,12 @@ inline bool insidePolygon(std::span<const Vector2> vertices,

Vector2 distance = closestPoint - point;

return tolerance.isTolerated(distance, jacobianOpt);
if (mode == Extend) {
return tolerance.isTolerated(distance, jacobianOpt);
} else {
// @TODO: Check sign
return tolerance.isTolerated(-distance, jacobianOpt) && insidePolygon;
}
}

} // namespace Acts::detail
Loading

0 comments on commit b4817ab

Please sign in to comment.