From a4517c75cadbfe9a66cc5428558582cb0cb32102 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Wed, 22 May 2024 15:07:04 +0200 Subject: [PATCH] refactor: Early exit for `CylinderBounds::inside` --- Core/src/Surfaces/CylinderBounds.cpp | 76 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/Core/src/Surfaces/CylinderBounds.cpp b/Core/src/Surfaces/CylinderBounds.cpp index 64d13bb688a..b66ecec9065 100644 --- a/Core/src/Surfaces/CylinderBounds.cpp +++ b/Core/src/Surfaces/CylinderBounds.cpp @@ -48,47 +48,49 @@ bool Acts::CylinderBounds::inside(const Vector2& lposition, double halfLengthZ = get(eHalfLengthZ); double halfPhi = get(eHalfPhiSector); - if (bevelMinZ != 0. && bevelMaxZ != 0.) { - double radius = get(eR); - // Beleved sides will unwrap to a trapezoid - /////////////////////////////////// - // ________ - // /| . . |\ r/phi - // \|______|/ r/phi - // -Z 0 Z - /////////////////////////////////// - float localx = - lposition[0] > radius ? 2 * radius - lposition[0] : lposition[0]; - Vector2 shiftedlposition = shifted(lposition); - if ((std::fabs(shiftedlposition[0]) <= halfPhi && - std::fabs(shiftedlposition[1]) <= halfLengthZ)) { - return true; - } else if ((lposition[1] >= - -(localx * std::tan(bevelMinZ) + halfLengthZ)) && - (lposition[1] <= (localx * std::tan(bevelMaxZ) + halfLengthZ))) { - return true; - } else { - // check within tolerance - auto boundaryCheck = bcheck.transformed(jacobian()); - - Vector2 lowerLeft = {-radius, -halfLengthZ}; - Vector2 middleLeft = {0., -(halfLengthZ + radius * std::tan(bevelMinZ))}; - Vector2 upperLeft = {radius, -halfLengthZ}; - Vector2 upperRight = {radius, halfLengthZ}; - Vector2 middleRight = {0., (halfLengthZ + radius * std::tan(bevelMaxZ))}; - Vector2 lowerRight = {-radius, halfLengthZ}; - Vector2 vertices[] = {lowerLeft, middleLeft, upperLeft, - upperRight, middleRight, lowerRight}; - Vector2 closestPoint = - boundaryCheck.computeClosestPointOnPolygon(lposition, vertices); - - return boundaryCheck.isTolerated(closestPoint - lposition); - } - } else { + + if (bevelMinZ == 0. || bevelMaxZ == 0.) { return bcheck.transformed(jacobian()) .isInside(shifted(lposition), Vector2(-halfPhi, -halfLengthZ), Vector2(halfPhi, halfLengthZ)); } + + double radius = get(eR); + // Beleved sides will unwrap to a trapezoid + /////////////////////////////////// + // ________ + // /| . . |\ r/phi + // \|______|/ r/phi + // -Z 0 Z + /////////////////////////////////// + float localx = + lposition[0] > radius ? 2 * radius - lposition[0] : lposition[0]; + Vector2 shiftedlposition = shifted(lposition); + if ((std::fabs(shiftedlposition[0]) <= halfPhi && + std::fabs(shiftedlposition[1]) <= halfLengthZ)) { + return true; + } + + if ((lposition[1] >= -(localx * std::tan(bevelMinZ) + halfLengthZ)) && + (lposition[1] <= (localx * std::tan(bevelMaxZ) + halfLengthZ))) { + return true; + } + + // check within tolerance + auto boundaryCheck = bcheck.transformed(jacobian()); + + Vector2 lowerLeft = {-radius, -halfLengthZ}; + Vector2 middleLeft = {0., -(halfLengthZ + radius * std::tan(bevelMinZ))}; + Vector2 upperLeft = {radius, -halfLengthZ}; + Vector2 upperRight = {radius, halfLengthZ}; + Vector2 middleRight = {0., (halfLengthZ + radius * std::tan(bevelMaxZ))}; + Vector2 lowerRight = {-radius, halfLengthZ}; + Vector2 vertices[] = {lowerLeft, middleLeft, upperLeft, + upperRight, middleRight, lowerRight}; + Vector2 closestPoint = + boundaryCheck.computeClosestPointOnPolygon(lposition, vertices); + + return boundaryCheck.isTolerated(closestPoint - lposition); } bool Acts::CylinderBounds::inside3D(const Vector3& position,