Commit bdb7e876 authored by Martin Kostelnik's avatar Martin Kostelnik Committed by Andrei Gheata
Browse files

Fix types in ConventionChecker and ApproxEqual

parent c5f4d1a1
......@@ -56,7 +56,7 @@ void ShapeTester<ImplT>::SetNumDisp(int num)
// Helper function taken from ApproxEqual.h
template <typename ImplT>
bool ShapeTester<ImplT>::ApproxEqual(const double x, const double y)
bool ShapeTester<ImplT>::ApproxEqual(const double &x, const double &y)
{
if (x == y) {
return true;
......@@ -70,6 +70,21 @@ bool ShapeTester<ImplT>::ApproxEqual(const double x, const double y)
}
}
template <typename ImplT>
bool ShapeTester<ImplT>::ApproxEqual(const float &x, const float &y)
{
if (x == y) {
return true;
} else if (x * y == 0.0) {
float diff = std::fabs(x - y);
return diff < kApproxEqualTolerance;
} else {
float diff = std::fabs(x - y);
float abs_x = std::fabs(x), abs_y = std::fabs(y);
return diff / (abs_x + abs_y) < kApproxEqualTolerance;
}
}
// Return true if the 3vector check is approximately equal to target
template <typename ImplT>
template <class Vec_t>
......@@ -130,7 +145,7 @@ bool ShapeTester<ImplT>::ShapeConventionSurfacePoint()
// bool valid =
fVolume->Normal(point, normal);
double Dist = fVolume->DistanceToIn(point, direction);
Precision Dist = fVolume->DistanceToIn(point, direction);
// if (Dist >= kInfLength) Dist = kInfLength;
int indx = 0;
......@@ -240,7 +255,7 @@ bool ShapeTester<ImplT>::ShapeConventionInsidePoint()
{
int nError = 0;
double Dist;
Precision Dist;
bool insidePointConventionPassed = true;
......@@ -311,12 +326,13 @@ template <typename ImplT>
bool ShapeTester<ImplT>::ShapeConventionOutsidePoint()
{
int nError = 0;
double Dist;
Precision Dist, DistBB;
bool outsidePointConventionPassed = true;
for (int i = 0; i < fMaxPointsOutside; i++) { // test SamplePointOnSurface()
Vec_t point = fPoints[fOffsetOutside + i];
Vec_t pointBB;
Vec_t direction = fDirections[fOffsetOutside + i];
if (fVolume->Inside(point) != vecgeom::EInside::kOutside) {
ReportError(&nError, point, direction, 0.,
......@@ -325,7 +341,9 @@ bool ShapeTester<ImplT>::ShapeConventionOutsidePoint()
int indx = 10;
// Convention Check for DistanceToIn
Dist = fVolume->DistanceToIn(point, direction);
DistBB = fVolume->GetUnplacedVolume()->ApproachSolid(point, 1 / direction);
pointBB = point + DistBB * direction;
Dist = fVolume->DistanceToIn(pointBB, direction) + DistBB;
// if (Dist >= kInfLength) Dist = kInfLength;
if (!(Dist > 0.)) {
ReportError(&nError, point, direction, Dist, "DistanceToIn for Outside Point should be > 0.");
......
......@@ -90,6 +90,7 @@ void ShapeTester<ImplT>::SetDefaults()
fVisualize = false;
fSolidTolerance = vecgeom::kTolerance;
fSolidFarAway = vecgeom::kFarAway;
fStat = false;
fTestBoundaryErrors = true;
fDebug = false;
......@@ -705,7 +706,7 @@ int ShapeTester<ImplT>::TestFarAwayPoint()
point1 = point;
// Move point far away
point1 = point1 + vec * kFarAway;
point1 = point1 + vec * fSolidFarAway;
// Shoot back to solid, then compute point on surface
distBB = fVolume->GetUnplacedVolume()->ApproachSolid(point1, -1 / vec);
pointBB = point1 - distBB * vec;
......@@ -925,7 +926,7 @@ int ShapeTester<ImplT>::TestInsidePoint()
continue;
}
// Distance to out from inside point should be bigger than the safety
if (dist < safeDistance - 1E-10) {
if (dist < safeDistance - fSolidTolerance) {
ReportError(&nError, point, v, safeDistance, "TI: DistanceToOut(p,v) < DistanceToIn(p)");
continue;
}
......@@ -1223,7 +1224,7 @@ int ShapeTester<ImplT>::TestAccuracyDistanceToIn(Precision dist)
ClearErrors();
int iIn = 0, iInNoSurf = 0, iOut = 0, iOutNoSurf = 0;
int iInInf = 0, iInZero = 0;
Precision tolerance = kTolerance;
Precision tolerance = fSolidTolerance;
#ifdef VECGEOM_ROOT
// Histograms
......
......@@ -51,7 +51,8 @@ public:
inline void SetOutsideMaxRadiusMultiple(const Precision percent) { fOutsideMaxRadiusMultiple = percent; }
inline void SetOutsideRandomDirectionPercent(const Precision percent) { fOutsideRandomDirectionPercent = percent; }
inline void SetSaveAllData(const bool safe) { fIfSaveAllData = safe; }
inline void SetSolidTolerance(Precision value) { fSolidTolerance = value; }
inline void SetSolidTolerance(const Precision value) { fSolidTolerance = value; }
inline void SetSolidFarAway(const Precision value) { fSolidFarAway = value; }
inline void SetTestBoundaryErrors(bool flag) { fTestBoundaryErrors = flag; }
void SetFolder(const std::string &newFolder);
void SetVerbose(int verbose) { fVerbose = verbose; }
......@@ -166,7 +167,8 @@ private:
bool ShapeConventionInsidePoint(); // Function to check conventions for Inside Points
bool ShapeConventionOutsidePoint(); // Function to check conventions for Outside Points
void SetNumDisp(int); // Function to set num. of points to be displayed during convention failure
bool ApproxEqual(const double x, const double y); // Helper function to check approximate equality
bool ApproxEqual(const double &x, const double &y); // Helper function to check approximate equality of doubles
bool ApproxEqual(const float &x, const float &y); // Helper function to check approximate equality of floats
// Return true if the 3vector check is approximately equal to target
template <class Vec_t>
bool ApproxEqual(const Vec_t &check, const Vec_t &target);
......@@ -236,6 +238,7 @@ private:
bool fVisualize; // Flag to be set or unset by EnableDebugger() function that user will
// call with true parameter if want to see visualization in case of some mismatch
Precision fSolidTolerance; // Tolerance on boundary declared by solid (default kTolerance)
Precision fSolidFarAway; // Distance to shoot points at from solid in TestFarAwayPoints
#ifdef VECGEOM_ROOT
vecgeom::Visualizer fVisualizer; // Visualizer object to visualize the geometry if fVisualize is set.
#endif
......
......@@ -33,6 +33,9 @@ int runTester(ImplT const *shape, int npoints, bool debug, bool stat)
ShapeTester<ImplT> tester;
tester.setDebug(debug);
#ifdef VECGEOM_FLOAT_PRECISION
tester.SetSolidTolerance(1.e-4);
#endif
tester.setStat(stat);
tester.SetMaxPoints(npoints);
int errcode = tester.Run(shape);
......
......@@ -51,14 +51,14 @@ bool ApproxEqual<float>(const float &x, const float &y)
if (x == y) {
return true;
} else if (x * y == 0.0) {
double diff = std::fabs(x - y);
float diff = std::fabs(x - y);
return diff < kApproxEqualToleranceFlt;
} else if (fabs(x) > 1.0e+100 || fabs(y) > 1.0e+100) {
// handle comparisons to infinity
return (x * y > 0) && fabs(x) > 1.0e+100 && fabs(y) > 1.0e+100;
} else {
double diff = std::fabs(x - y);
double abs_x = std::fabs(x), abs_y = std::fabs(y);
float diff = std::fabs(x - y);
float abs_x = std::fabs(x), abs_y = std::fabs(y);
return diff / (abs_x + abs_y) < kApproxEqualToleranceFlt;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment