// (c) Tuomas J. Lukka namespace Vob { namespace Opt { /** A simple 1D zero finder that starts with two points where the function must * have a different sign. */ template float findZero1D(const F &f, float low, float high, float epsx, float epsf, bool &success) { float fl = F(low); float fh = F(high); if(fl * fh >= 0) { success = false; return low; } while(fabs(high - low) >= epsx && fabs(fh - fl) >= epsf) { float mid = lerp(low, high, .5); float fm = F(mid); if(fm * fl >= 0) { low = mid; fl = fm; } else { high = mid; fh = fm; } } success = true; return lerp(low, high, .5); } } }