Skip to content

Commit 6ec280b

Browse files
committed
[math] redefining PI
1 parent c9bc8f6 commit 6ec280b

File tree

6 files changed

+50
-54
lines changed

6 files changed

+50
-54
lines changed

src/core/tools/codac2_math.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99

1010
#pragma once
1111

12-
//#include <numbers>
13-
#include <3rd/gaol/gaol_port.h>
12+
#include <numbers>
1413

1514
namespace codac2
1615
{
17-
// As long as GAOL defines pi in common namespace,
18-
// we use it as default pi value instead of the pi
19-
// from the standard library.
20-
//constexpr double pi = std::numbers::pi; // Need C++20
16+
constexpr double PI = std::numbers::pi; // Need C++20
2117
}

src/graphics/3rd/vibes/codac2_Figure2D_VIBes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,28 @@ void Figure2D_VIBes::draw_pie(const Vector& c, const Interval& r, const Interval
118118
assert(_fig.size() <= c.size());
119119
assert(r.lb() >= 0.);
120120
// Corrected a bug in VIBEs in case of r=[..,oo] (the pie disappears when zoomed in)
121-
vibes::drawPie(c[i()],c[j()], r.lb(),(r.ub()>1e5?1e5:r.ub()), 180.*theta.lb()/pi,180.*theta.ub()/pi, to_vibes_style(s), _params);
121+
vibes::drawPie(c[i()],c[j()], r.lb(),(r.ub()>1e5?1e5:r.ub()), 180.*theta.lb()/PI,180.*theta.ub()/PI, to_vibes_style(s), _params);
122122
}
123123

124124
void Figure2D_VIBes::draw_ellipse(const Vector& c, const Vector& ab, double theta, const StyleProperties& s)
125125
{
126126
assert(c.size() == 2);
127127
assert(ab.size() == 2);
128-
vibes::drawEllipse(c[0],c[1], ab[0],ab[1], 180.*theta/pi, to_vibes_style(s), _params);
128+
vibes::drawEllipse(c[0],c[1], ab[0],ab[1], 180.*theta/PI, to_vibes_style(s), _params);
129129
}
130130

131131
void Figure2D_VIBes::draw_tank(const Vector& x, float size, const StyleProperties& s)
132132
{
133133
assert(_fig.size() <= x.size()+1);
134134
assert(j()+1 < x.size());
135-
vibes::drawTank(x[i()],x[j()],180.*x[j()+1]/pi, size, to_vibes_style(s), _params);
135+
vibes::drawTank(x[i()],x[j()],180.*x[j()+1]/PI, size, to_vibes_style(s), _params);
136136
}
137137

138138
void Figure2D_VIBes::draw_AUV(const Vector& x, float size, const StyleProperties& s)
139139
{
140140
assert(_fig.size() <= x.size()+1);
141141
assert(j()+1 < x.size());
142-
vibes::drawAUV(x[i()],x[j()],180.*x[j()+1]/pi, size, to_vibes_style(s), _params);
142+
vibes::drawAUV(x[i()],x[j()],180.*x[j()+1]/PI, size, to_vibes_style(s), _params);
143143
}
144144

145145
string Figure2D_VIBes::to_vibes_style(const StyleProperties& s)

src/graphics/figures/codac2_Figure2D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void Figure2D::draw_pie(const Vector& c, const Interval& r, const Interval& thet
178178

179179
Interval theta_(theta);
180180
if(theta.is_unbounded())
181-
theta_ = Interval(0,2.*pi);
181+
theta_ = Interval(0,2.*PI);
182182

183183
Interval r_(r);
184184
if(r.is_unbounded())

tests/core/domains/interval/codac2_tests_Interval_bwd.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,25 @@ TEST_CASE("Interval bwd operations")
261261

262262
Interval a, y;
263263

264-
a = Interval(pi/6.,pi/3.); y = Interval(.5,10.); x = Interval(.5,2.);
264+
a = Interval(PI/6.,PI/3.); y = Interval(.5,10.); x = Interval(.5,2.);
265265
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(.5,2.*sqrt(3.))); CHECK(Approx(x) == Interval(.5,2.));
266-
a = Interval(pi/6.,pi/3.); y = Interval(.5,2.); x = Interval(.5,10.);
266+
a = Interval(PI/6.,PI/3.); y = Interval(.5,2.); x = Interval(.5,10.);
267267
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(.5,2.)); CHECK(Approx(x) == Interval(.5,2.*sqrt(3.)));
268-
a = Interval(-pi/4.,pi/4.); y = Interval(1.,2.); x = Interval(.5,2.);
268+
a = Interval(-PI/4.,PI/4.); y = Interval(1.,2.); x = Interval(.5,2.);
269269
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(1.,2.)); CHECK(Approx(x) == Interval(1.,2.));
270-
a = Interval(-pi/2.,0.); y = Interval(.5,2.); x = Interval(.5,10.);
270+
a = Interval(-PI/2.,0.); y = Interval(.5,2.); x = Interval(.5,10.);
271271
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval::empty()); CHECK(Approx(x) == Interval::empty());
272-
a = Interval(2.*pi,3.*pi); y = Interval(-.5,2.); x = Interval(.5,10.);
272+
a = Interval(2.*PI,3.*PI); y = Interval(-.5,2.); x = Interval(.5,10.);
273273
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval::empty()); CHECK(Approx(x) == Interval::empty());
274-
a = Interval(2*pi/3.,5.*pi/6.); y = Interval(0.,100.); x = Interval(-20.,-sqrt(3.)/2.);
274+
a = Interval(2*PI/3.,5.*PI/6.); y = Interval(0.,100.); x = Interval(-20.,-sqrt(3.)/2.);
275275
bwd_atan2(a,y,x); CHECK(Approx(y,1e-10) == Interval(.5,20.*sqrt(3.))); CHECK(Approx(x) == Interval(-20.,-sqrt(3.)/2));
276-
a = Interval(-3*pi/4.,-2*pi/3.); y = Interval(-sqrt(3.)/2.,2.); x = Interval(-sqrt(2.)/2.,0.);
276+
a = Interval(-3*PI/4.,-2*PI/3.); y = Interval(-sqrt(3.)/2.,2.); x = Interval(-sqrt(2.)/2.,0.);
277277
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(-sqrt(3.)/2.,0.)); CHECK(Approx(x) == Interval(-sqrt(2.)/2.,0.));
278-
a = Interval(-3*pi/4.,-2*pi/3.); y = Interval(-sqrt(3.)/2.,2.); x = Interval(-1.,-.5);
278+
a = Interval(-3*PI/4.,-2*PI/3.); y = Interval(-sqrt(3.)/2.,2.); x = Interval(-1.,-.5);
279279
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(-sqrt(3.)/2.,-.5)); CHECK(Approx(x) == Interval(-sqrt(3.)/2.,-.5));
280-
a = Interval(-3*pi/4.,-pi/4.); y = Interval(-5.,-.5); x = Interval(-oo,oo);
280+
a = Interval(-3*PI/4.,-PI/4.); y = Interval(-5.,-.5); x = Interval(-oo,oo);
281281
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(-5.,-.5)); CHECK(Approx(x) == Interval(-5.,5.));
282-
a = Interval(-pi/3.,pi/4.); y = Interval(-oo,oo); x = Interval(sqrt(3.)/2.);
282+
a = Interval(-PI/3.,PI/4.); y = Interval(-oo,oo); x = Interval(sqrt(3.)/2.);
283283
bwd_atan2(a,y,x); CHECK(Approx(y) == Interval(-1.5,sqrt(3.)/2.)); CHECK(Approx(x) == Interval(sqrt(3.)/2.));
284284
a = Interval::half_pi(); y = Interval(1); x = 0.;
285285
bwd_atan2(a,y,x); CHECK(Approx(y) == 1.); CHECK(Approx(x) == 0.);
@@ -292,15 +292,15 @@ TEST_CASE("Interval bwd operations")
292292
x = Interval(-1,5); bwd_sqrt(Interval(2,5), x); CHECK(x == Interval(4,5));
293293
x = Interval(-oo,oo); bwd_sqrt(Interval(-4,-2), x); CHECK(x == Interval::empty());
294294

295-
x = Interval(-1.,3.); bwd_atan(Interval(0.,pi/6.),x); CHECK(x == tan(Interval(0.,pi/6.)));
296-
x = Interval(0,5*pi/2.0); bwd_atan(Interval(-pi,1.5),x); CHECK(x == Interval(0,5*pi/2.0));
297-
x = Interval(.2,.5); bwd_atan(Interval(0.,pi/6.),x); CHECK(x == Interval(.2,.5));
298-
x = Interval(-100,100); bwd_atan(Interval(-pi/2-0.1,pi/2+0.1),x); CHECK(x == Interval(-100,100));
299-
x = Interval(-100,100); bwd_atan(Interval(pi/2+0.1,pi),x); CHECK(x == Interval::empty());
300-
x = Interval(-100,100); bwd_atan(Interval(-pi,-pi/2-0.1),x); CHECK(x == Interval::empty());
295+
x = Interval(-1.,3.); bwd_atan(Interval(0.,PI/6.),x); CHECK(x == tan(Interval(0.,PI/6.)));
296+
x = Interval(0,5*PI/2.0); bwd_atan(Interval(-PI,1.5),x); CHECK(x == Interval(0,5*PI/2.0));
297+
x = Interval(.2,.5); bwd_atan(Interval(0.,PI/6.),x); CHECK(x == Interval(.2,.5));
298+
x = Interval(-100,100); bwd_atan(Interval(-PI/2-0.1,PI/2+0.1),x); CHECK(x == Interval(-100,100));
299+
x = Interval(-100,100); bwd_atan(Interval(PI/2+0.1,PI),x); CHECK(x == Interval::empty());
300+
x = Interval(-100,100); bwd_atan(Interval(-PI,-PI/2-0.1),x); CHECK(x == Interval::empty());
301301

302-
x = Interval(-oo,oo); bwd_atan(Interval(-pi/4,pi/2.), x); CHECK(x.lb() == -1); CHECK(x.ub() > 1000);
303-
x = Interval(-oo,oo); bwd_atan(Interval(-pi/2,pi/4.), x); CHECK(x.ub() == +1); CHECK(x.lb() < -1000);
302+
x = Interval(-oo,oo); bwd_atan(Interval(-PI/4,PI/2.), x); CHECK(x.lb() == -1); CHECK(x.ub() > 1000);
303+
x = Interval(-oo,oo); bwd_atan(Interval(-PI/2,PI/4.), x); CHECK(x.ub() == +1); CHECK(x.lb() < -1000);
304304

305305
CHECK_bwd_add(Interval(1,3),Interval(1,2),Interval(-10,5),Interval(1,2),Interval(-1,2));
306306
CHECK_bwd_add(Interval::empty(),Interval(0.1,2.0),Interval(-10,2),Interval::empty(),Interval::empty());
@@ -317,11 +317,11 @@ TEST_CASE("Interval bwd operations")
317317
CHECK_bwd_imod(3.,Interval(3.,5.),Interval(1.,2.),Interval(4.,5.),Interval(1.,2.));
318318
CHECK_bwd_imod(2.,Interval(7.,8.),Interval(.5,2.),Interval(7.,8.),Interval(1.,2.));
319319
CHECK_bwd_imod(2.,Interval(7.,8.),Interval(0.,2.),Interval(7.,8.),Interval(0.,2.));
320-
CHECK_bwd_imod(2.*pi,Interval(2.*pi,3.*pi),Interval(pi/6,pi/2.),Interval(13.*pi/6.,5.*pi/2.),Interval(pi/6,pi/2.));
321-
CHECK_bwd_imod(2.*pi,Interval(3.*pi,4.*pi),Interval(pi/3,pi/2.),Interval::empty(),Interval::empty());
322-
CHECK_bwd_imod(2.*pi,Interval(3.*pi,4.*pi),Interval(0.,pi/2.),Interval(4*pi),Interval(0.));
323-
CHECK_bwd_imod(2.*pi,Interval(2.*pi,4.*pi),Interval(-pi/6,pi/2.),Interval(2.*pi,4.*pi),Interval(-pi/6,pi/2.));
324-
CHECK_bwd_imod(2.*pi,Interval(7.*pi/4.,8.*pi/3),Interval(-pi/2,pi/2.),Interval(7.*pi/4.,5.*pi/2.),Interval(-pi/4,pi/2.));
320+
CHECK_bwd_imod(2.*PI,Interval(2.*PI,3.*PI),Interval(PI/6,PI/2.),Interval(13.*PI/6.,5.*PI/2.),Interval(PI/6,PI/2.));
321+
CHECK_bwd_imod(2.*PI,Interval(3.*PI,4.*PI),Interval(PI/3,PI/2.),Interval::empty(),Interval::empty());
322+
CHECK_bwd_imod(2.*PI,Interval(3.*PI,4.*PI),Interval(0.,PI/2.),Interval(4*PI),Interval(0.));
323+
CHECK_bwd_imod(2.*PI,Interval(2.*PI,4.*PI),Interval(-PI/6,PI/2.),Interval(2.*PI,4.*PI),Interval(-PI/6,PI/2.));
324+
CHECK_bwd_imod(2.*PI,Interval(7.*PI/4.,8.*PI/3),Interval(-PI/2,PI/2.),Interval(7.*PI/4.,5.*PI/2.),Interval(-PI/4,PI/2.));
325325

326326
x = Interval(-oo,oo); bwd_floor(Interval::empty(),x); CHECK(x == Interval::empty());
327327
x = Interval(-oo,-0.000001); bwd_floor(Interval(-oo,-1),x); CHECK(x == Interval(-oo,-0.000001));

tests/core/functions/analytic/codac2_tests_AnalyticFunction.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,47 +148,47 @@ TEST_CASE("AnalyticFunction")
148148
//.def(py::self + py::self);
149149
CHECK(Approx(AnalyticFunction({x1}, cos(x1)+cos(x1)).eval(m, Interval(0.))) == Interval(2.));
150150
//.def("__add__", {}(const ScalarExpr& e1, const ScalarVar& e2);
151-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)+x1).eval(m, pi)) == pi-1);
151+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)+x1).eval(m, PI)) == PI-1);
152152
//.def("__radd__", {}(const ScalarExpr& e1, const ScalarVar& e2);
153-
CHECK(Approx(AnalyticFunction({x1}, x1+cos(x1)).eval(m, pi)) == pi-1);
153+
CHECK(Approx(AnalyticFunction({x1}, x1+cos(x1)).eval(m, PI)) == PI-1);
154154
//.def("__add__", {}(const ScalarExpr& e1, const Interval& e2);
155-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)+Interval(10.)).eval(m, pi)) == Interval(9));
155+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)+Interval(10.)).eval(m, PI)) == Interval(9));
156156
//.def("__radd__", {}(const ScalarExpr& e1, const Interval& e2);
157-
CHECK(Approx(AnalyticFunction({x1}, 10+cos(x1)).eval(m, pi)) == Interval(9));
157+
CHECK(Approx(AnalyticFunction({x1}, 10+cos(x1)).eval(m, PI)) == Interval(9));
158158
//.def(- py::self);
159159
CHECK(Approx(AnalyticFunction({x1}, -cos(x1)).eval(m, Interval(0.))) == Interval(-1.));
160160
//.def(py::self - py::self);
161161
CHECK(Approx(AnalyticFunction({x1}, cos(x1)-cos(x1)).eval(m, Interval(0.))) == Interval(0.));
162162
//.def("__sub__", {}(const ScalarExpr& e1, const ScalarVar& e2);
163-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)-x1).eval(m, pi)) == -pi-1);
163+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)-x1).eval(m, PI)) == -PI-1);
164164
//.def("__rsub__", {}(const ScalarExpr& e1, const ScalarVar& e2);
165-
CHECK(Approx(AnalyticFunction({x1}, x1-cos(x1)).eval(m, pi)) == pi+1);
165+
CHECK(Approx(AnalyticFunction({x1}, x1-cos(x1)).eval(m, PI)) == PI+1);
166166
//.def("__sub__", {}(const ScalarExpr& e1, const Interval& e2);
167-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)-Interval(10.)).eval(m, pi)) == -Interval(11));
167+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)-Interval(10.)).eval(m, PI)) == -Interval(11));
168168
//.def("__rsub__", {}(const ScalarExpr& e1, const Interval& e2);
169-
CHECK(Approx(AnalyticFunction({x1}, 10-cos(x1)).eval(m, pi)) == Interval(11));
169+
CHECK(Approx(AnalyticFunction({x1}, 10-cos(x1)).eval(m, PI)) == Interval(11));
170170
//.def(py::self * py::self);
171171
CHECK(Approx(AnalyticFunction({x1}, cos(x1)*cos(x1)).eval(m, Interval(0.))) == Interval(1.));
172172
//.def("__mul__", {}(const ScalarExpr& e1, const ScalarVar& e2);
173-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)*x1).eval(m, pi)) == -1*pi);
173+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)*x1).eval(m, PI)) == -1*PI);
174174
//.def("__rmul__", {}(const ScalarExpr& e1, const ScalarVar& e2);
175-
CHECK(Approx(AnalyticFunction({x1}, x1*cos(x1)).eval(m, pi)) == -1*pi);
175+
CHECK(Approx(AnalyticFunction({x1}, x1*cos(x1)).eval(m, PI)) == -1*PI);
176176
//.def("__mul__", {}(const ScalarExpr& e1, const Interval& e2);
177-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)*Interval(10.)).eval(m, pi),1e-9) == -Interval(10));
177+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)*Interval(10.)).eval(m, PI),1e-9) == -Interval(10));
178178
//.def("__rmul__", {}(const ScalarExpr& e1, const Interval& e2);
179-
CHECK(Approx(AnalyticFunction({x1}, Interval(10.)*cos(x1)).eval(m, pi),1e-9) == -10);
179+
CHECK(Approx(AnalyticFunction({x1}, Interval(10.)*cos(x1)).eval(m, PI),1e-9) == -10);
180180
//.def("__mul__", {}(const ScalarExpr& e1, const VectorExpr& e2);
181-
CHECK(Approx(AnalyticFunction({v1,v2}, cos(v1[0])*(v2+v2)).eval(m, Vector({pi,-1}),Vector({2,3})),1e-9) == IntervalVector({-4,-6}));
181+
CHECK(Approx(AnalyticFunction({v1,v2}, cos(v1[0])*(v2+v2)).eval(m, Vector({PI,-1}),Vector({2,3})),1e-9) == IntervalVector({-4,-6}));
182182
//.def("__truediv__", {}(const ScalarExpr& e1, const ScalarExpr& e2);
183183
CHECK(Approx(AnalyticFunction({x1}, cos(x1)/cos(x1)).eval(m, Interval(0.))) == Interval(1.));
184184
//.def("__truediv__", {}(const ScalarExpr& e1, const ScalarVar& e2);
185-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)/x1).eval(m, pi)) == -1/pi);
185+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)/x1).eval(m, PI)) == -1/PI);
186186
//.def("__rtruediv__", {}(const ScalarExpr& e1, const ScalarVar& e2);
187-
CHECK(Approx(AnalyticFunction({x1}, x1/cos(x1)).eval(m, pi)) == -pi);
187+
CHECK(Approx(AnalyticFunction({x1}, x1/cos(x1)).eval(m, PI)) == -PI);
188188
//.def("__truediv__", {}(const ScalarExpr& e1, const Interval& e2);
189-
CHECK(Approx(AnalyticFunction({x1}, cos(x1)/Interval(4.)).eval(m, pi)) == -1./4);
189+
CHECK(Approx(AnalyticFunction({x1}, cos(x1)/Interval(4.)).eval(m, PI)) == -1./4);
190190
//.def("__rtruediv__", {}(const ScalarExpr& e1, const Interval& e2);
191-
CHECK(Approx(AnalyticFunction({x1}, 4./cos(x1)).eval(m, pi)) == -4);
191+
CHECK(Approx(AnalyticFunction({x1}, 4./cos(x1)).eval(m, PI)) == -4);
192192

193193
// ======> VectorExpr
194194

@@ -218,7 +218,7 @@ TEST_CASE("AnalyticFunction")
218218
//.def("__rsub__", {}(const VectorExpr& e1, const IntervalVector& e2);
219219
CHECK(Approx(AnalyticFunction({v1,v2}, Vector({1,5})-(v1-v2)).eval(m, IntervalVector({2,3}),Vector({1,5}))) == IntervalVector({0,7}));
220220
//.def("__rmul__", {}(const VectorExpr& e1, const ScalarExpr& e2);
221-
CHECK(Approx(AnalyticFunction({v1,v2}, cos(v1[0])*(v2+v2)).eval(m, Vector({pi,-1}),Vector({2,3})),1e-9) == IntervalVector({-4,-6}));
221+
CHECK(Approx(AnalyticFunction({v1,v2}, cos(v1[0])*(v2+v2)).eval(m, Vector({PI,-1}),Vector({2,3})),1e-9) == IntervalVector({-4,-6}));
222222
//.def("__rmul__", {}(const VectorExpr& e1, const ScalarVar& e2);
223223
CHECK(Approx(AnalyticFunction({x1}, x1*vec(3*x1,2*x1)).eval(m, 3),1e-9) == IntervalVector({27,18}));
224224
}

tests/core/trajectory/codac2_tests_SampledTrajectory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ TEST_CASE("SampledTrajectory as operator (1d case)")
6767
{
6868
ScalarVar t;
6969
AnalyticFunction f { {t}, cos(t) };
70-
AnalyticTrajectory analytic_traj(f, {-pi,pi});
70+
AnalyticTrajectory analytic_traj(f, {-PI,PI});
7171
auto sampled_traj = analytic_traj.sampled(1e-2);
7272
auto g = sampled_traj.as_function();
7373

7474
AnalyticFunction h { {t}, g(t) };
7575

76-
for(double t = -pi ; t < pi ; t+=1e-2)
76+
for(double t = -PI ; t < PI ; t+=1e-2)
7777
CHECK(Approx(h.real_eval(t)) == cos(t));
7878
}
7979

0 commit comments

Comments
 (0)