kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #36912
Re: MacOS build issue with new geometry tests
Hi Adam,
Sorry, this in my stuff - I though that was a way to get PI without
having to guess the setting of _USE_MATH_DEFINES or do #ifdefs like at
the top of dl_codes.h, but obviously not.
The attached patch might work, but I can't test on a Mac, so all I can
say is "it builds for me and the tests pass". Specifically,
_USE_MATH_DEFINES may need to be set for qa_geometry if not already.
Cheers,
John
On Sun, Jul 29, 2018 at 1:38 PM, Adam Wolf
<adamwolf@xxxxxxxxxxxxxxxxxxxx> wrote:
> Hi folks!
>
> There's a build failure on the new geometry test stuff with MacOS.
>
> qa/geometry/geom_test_utils.h:33:18: error: constexpr variable 'PI'
> must be initialized by a constant expression
> constexpr double PI = atan(1.0) * 4.0;
> ^ ~~~~~~~~~~~~~~~
> qa/geometry/geom_test_utils.h:33:23: note: non-constexpr function
> 'atan' cannot be used in a constant expression
> constexpr double PI = atan(1.0) * 4.0;
>
> There are a few others, all which look about the same. I am on my way
> out of town today so I don't have time to look for a solution, but a
> user actually reported it to me due to using the new MacOS build
> scripts! :D
>
> Adam Wolf
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
From 28d23f2c73a7f824ddb3474e46ea79071fe075a9 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Sun, 29 Jul 2018 16:29:02 +0100
Subject: [PATCH] Use M_PI for Pi, not constexpr calculation
Constexpr evaluation breaks Clang compilation.
Use math.h M_PI, as elsewhere.
---
qa/geometry/geom_test_utils.h | 11 +++++------
qa/geometry/test_fillet.cpp | 3 ++-
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/qa/geometry/geom_test_utils.h b/qa/geometry/geom_test_utils.h
index cb4e9721f..d598a24df 100644
--- a/qa/geometry/geom_test_utils.h
+++ b/qa/geometry/geom_test_utils.h
@@ -24,15 +24,14 @@
#ifndef GEOM_TEST_UTILS_H
#define GEOM_TEST_UTILS_H
+#include <math.h>
+
/**
* @brief Utility functions for testing geometry functions.
*/
namespace GEOM_TEST
{
-constexpr double PI = atan(1.0) * 4.0;
-constexpr double PI_2 = atan(1.0) * 2.0;
-
/**
* @brief Check if a value is within a tolerance of a nominal value
*
@@ -159,12 +158,12 @@ bool ArePerpendicular( const VECTOR2<T>& a, const VECTOR2<T>& b, double aToleran
auto angle = std::abs( a.Angle() - b.Angle() );
// Normalise: angles of 3*pi/2 are also perpendicular
- if (angle > PI)
+ if (angle > M_PI)
{
- angle -= PI;
+ angle -= M_PI;
}
- return IsWithin( angle, PI_2, aTolerance );
+ return IsWithin( angle, M_PI / 2.0, aTolerance );
}
/**
diff --git a/qa/geometry/test_fillet.cpp b/qa/geometry/test_fillet.cpp
index 10a7fe725..c7d758ec6 100644
--- a/qa/geometry/test_fillet.cpp
+++ b/qa/geometry/test_fillet.cpp
@@ -68,8 +68,9 @@ void TestFilletSegmentConstraints( const SEG& aSeg, VECTOR2I aRadCentre,
( diffC.EuclideanNorm() )( aRadius )( aError + 1 ) );
// Check 3: Mid-point -> radius centre perpendicular
+ const auto perpendularityMaxError = ( M_PI / 2 ) / 10;
BOOST_CHECK_PREDICATE( ArePerpendicular<int>,
- ( diffC )( aSeg.A - aSeg.B )( PI_2 / 10 ) );
+ ( diffC )( aSeg.A - aSeg.B )( perpendularityMaxError ) );
}
--
2.17.1
Follow ups
References