QA: Fix angle-equality predicate

This was sometimes accepting a wrong value on the "other side" of
the correct value. Only actually affected one test, which is fixed.
This commit is contained in:
John Beard 2025-05-31 19:08:06 +08:00
parent d8a935be1c
commit 1ad03f5717
2 changed files with 10 additions and 6 deletions

View File

@ -39,14 +39,18 @@ namespace KI_TEST
*
* @return value is in [( aNominal - aError ) % aWrap, ( aNominal + aError ) % aWrap]
*/
template <typename T> bool IsWithinWrapped( T aValue, T aNominal, T aWrap, T aError )
template <typename T>
bool IsWithinWrapped( T aValue, T aNominal, T aWrap, T aError )
{
double diff = std::fmod( aNominal - aValue + aWrap / 2.0, aWrap );
// Compute shortest signed distance on a ring
double diff = std::fmod( static_cast<double>( aValue - aNominal ), static_cast<double>( aWrap ) );
if( diff < 0 )
if( diff > aWrap / 2.0 )
diff -= aWrap;
else if( diff < -aWrap / 2.0 )
diff += aWrap;
return diff - aWrap / 2.0 <= aError;
return std::abs( diff ) <= aError;
}
/**

View File

@ -62,7 +62,7 @@ static void CheckArcGeom( const SHAPE_ARC& aArc, const ARC_PROPERTIES& aProps, c
{
// Angular error - note this can get quite large for very small arcs,
// as the integral position rounding has a relatively greater effect
const double angle_tol_deg = 1.0;
const double angle_tol_deg = 2.0;
// Position error - rounding to nearest integer
const int pos_tol = 1;
@ -401,7 +401,7 @@ static const std::vector<ARC_TTR_CASE> arc_ttr_cases = {
{ 1707, 1707 }, //end on second segment
135, //positive angle due to start/end
180,
225,
315,
1000,
{ { 0, 1414 }, { 1707, 1000 } },
}