45 template <
typename Real>
55 static bool Find(std::function<Real(Real)>
const& F, Real
t0, Real
t1,
56 unsigned int maxIterations, Real negFTolerance, Real posFTolerance,
57 Real stepTTolerance, Real convTTolerance, Real& root);
61 template <
typename Real>
63 Real
t0, Real
t1,
unsigned int maxIterations, Real negFTolerance,
64 Real posFTolerance, Real stepTTolerance, Real convTTolerance, Real& root)
69 || negFTolerance > (Real)0
70 || posFTolerance < (Real)0
71 || stepTTolerance < (Real)0
72 || convTTolerance < (Real)0)
79 if (negFTolerance <= f0 && f0 <= posFTolerance)
88 if (negFTolerance <= f1 && f1 <= posFTolerance)
111 Real t2 =
t0, t3 =
t0, f2 = f0;
112 bool prevBisected =
true;
115 for (
unsigned int i = 0; i < maxIterations; ++i)
117 Real fDiff01 = f0 - f1, fDiff02 = f0 - f2, fDiff12 = f1 - f2;
118 Real invFDiff01 = ((Real)1) / fDiff01;
120 if (fDiff02 != (Real)0 && fDiff12 != (Real)0)
123 Real infFDiff02 = ((Real)1) / fDiff02;
124 Real invFDiff12 = ((Real)1) / fDiff12;
126 t0 * f1 * f2 * invFDiff01 * infFDiff02 -
127 t1 * f0 * f2 * invFDiff01 * invFDiff12 +
128 t2 * f0 * f1 * infFDiff02 * invFDiff12;
133 s = (t1 * f0 - t0 * f1) * invFDiff01;
137 Real tDiffSAvr = s - ((Real)0.75) * t0 - ((Real)0.25) *
t1;
138 Real tDiffS1 = s -
t1;
139 Real absTDiffS1 =
std::abs(tDiffS1);
140 Real absTDiff12 =
std::abs(t1 - t2);
141 Real absTDiff23 =
std::abs(t2 - t3);
143 bool currBisected =
false;
144 if (tDiffSAvr * tDiffS1 > (Real)0)
151 else if (prevBisected)
156 (absTDiffS1 >= ((Real)0.5) * absTDiff12) ||
157 (absTDiff12 <= stepTTolerance);
164 (absTDiffS1 >= ((Real)0.5) * absTDiff23) ||
165 (absTDiff23 <= stepTTolerance);
172 s = ((Real)0.5) * (t0 +
t1);
173 if (s == t0 || s == t1)
184 prevBisected =
false;
189 if (negFTolerance <= fs && fs <= posFTolerance)
199 if (f0 * fs < (Real)0)
212 if (
std::abs(t1 - t0) <= convTTolerance)
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
static bool Find(std::function< Real(Real)> const &F, Real t0, Real t1, unsigned int maxIterations, Real negFTolerance, Real posFTolerance, Real stepTTolerance, Real convTTolerance, Real &root)