mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 19:32:36 +08:00
SearchMin and BezierQuad: replace define with static constexpr (#10050)
This commit is contained in:
committed by
Daniel Agar
parent
6660418c31
commit
00e09524f7
@@ -41,9 +41,8 @@
|
|||||||
|
|
||||||
namespace bezier
|
namespace bezier
|
||||||
{
|
{
|
||||||
|
static constexpr double GOLDEN_RATIO = 1.6180339887; //(sqrt(5)+1)/2
|
||||||
#define GOLDEN_RATIO 1.61803398 //(sqrt(5)+1)/2
|
static constexpr double RESOLUTION = 0.0001; //End criterion for golden section search
|
||||||
#define RESOLUTION 0.0001 //represents resolution; end criterion for golden section search
|
|
||||||
|
|
||||||
template<typename Tp>
|
template<typename Tp>
|
||||||
void BezierQuad<Tp>::setBezier(const Vector3_t &pt0, const Vector3_t &ctrl, const Vector3_t &pt1,
|
void BezierQuad<Tp>::setBezier(const Vector3_t &pt0, const Vector3_t &ctrl, const Vector3_t &pt1,
|
||||||
|
|||||||
@@ -38,14 +38,13 @@
|
|||||||
* - Golden Section Search
|
* - Golden Section Search
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define GOLDEN_RATIO 1.6180339887 //(sqrt(5)+1)/2
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <platforms/px4_defines.h>
|
#include <platforms/px4_defines.h>
|
||||||
|
|
||||||
namespace math
|
namespace math
|
||||||
{
|
{
|
||||||
|
static constexpr double GOLDEN_RATIO = 1.6180339887; //(sqrt(5)+1)/2
|
||||||
|
|
||||||
// Type-safe abs
|
// Type-safe abs
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
@@ -60,8 +59,8 @@ inline const _Tp goldensection(const _Tp &arg1, const _Tp &arg2, _Tp(*fun)(_Tp),
|
|||||||
{
|
{
|
||||||
_Tp a = arg1;
|
_Tp a = arg1;
|
||||||
_Tp b = arg2;
|
_Tp b = arg2;
|
||||||
_Tp c = b - (b - a) / ((_Tp)GOLDEN_RATIO);
|
_Tp c = b - (b - a) / GOLDEN_RATIO;
|
||||||
_Tp d = a + (b - a) / ((_Tp)GOLDEN_RATIO);
|
_Tp d = a + (b - a) / GOLDEN_RATIO;
|
||||||
|
|
||||||
while (abs_t(c - d) > tol) {
|
while (abs_t(c - d) > tol) {
|
||||||
|
|
||||||
@@ -72,8 +71,8 @@ inline const _Tp goldensection(const _Tp &arg1, const _Tp &arg2, _Tp(*fun)(_Tp),
|
|||||||
a = c;
|
a = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = b - (b - a) / ((_Tp)GOLDEN_RATIO);
|
c = b - (b - a) / GOLDEN_RATIO;
|
||||||
d = a + (b - a) / ((_Tp)GOLDEN_RATIO);
|
d = a + (b - a) / GOLDEN_RATIO;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user