Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Early exit for CylinderBounds::inside #3207

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 39 additions & 37 deletions Core/src/Surfaces/CylinderBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
andiwand marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down