polynomial: rename solve as roots

This commit is contained in:
Danny Robson 2015-07-06 21:41:03 +10:00
parent 74d7f9c717
commit 3b97f56ead
4 changed files with 9 additions and 9 deletions

View File

@ -191,7 +191,7 @@ util::bezier<S>::intersections (point2f p0, point2f p1) const
pcoeff[i] = A * bcoeff[i].x + B * bcoeff[i].y; pcoeff[i] = A * bcoeff[i].x + B * bcoeff[i].y;
pcoeff.back () += C; pcoeff.back () += C;
const auto r = polynomial::solve<S> (pcoeff); const auto r = polynomial::roots<S> (pcoeff);
// The curve and line are colinear // The curve and line are colinear
if (std::all_of (r.begin (), r.end (), [] (auto i) { return std::isnan (i); })) if (std::all_of (r.begin (), r.end (), [] (auto i) { return std::isnan (i); }))
@ -261,7 +261,7 @@ namespace util {
float d = dot (M_, A); float d = dot (M_, A);
// We have our cubic, so pass off to the solver // We have our cubic, so pass off to the solver
auto solutions = util::polynomial::solve<3> ({a, b, c, d}); auto solutions = util::polynomial::roots<3> ({a, b, c, d});
// Find the smallest distance and return // Find the smallest distance and return
float dist = std::numeric_limits<float>::infinity (); float dist = std::numeric_limits<float>::infinity ();

View File

@ -30,7 +30,7 @@ static const size_t NEWTON_ITERATIONS = 1u;
namespace util { namespace polynomial { namespace util { namespace polynomial {
template <> template <>
std::array<float,1> std::array<float,1>
solve (std::array<float,2> coeff) roots (std::array<float,2> coeff)
{ {
const float a = coeff[0]; const float a = coeff[0];
const float b = coeff[1]; const float b = coeff[1];
@ -46,14 +46,14 @@ namespace util { namespace polynomial {
namespace util { namespace polynomial { namespace util { namespace polynomial {
template <> template <>
std::array<float,2> std::array<float,2>
solve (std::array<float,3> coeff) roots (std::array<float,3> coeff)
{ {
const float a = coeff[0]; const float a = coeff[0];
const float b = coeff[1]; const float b = coeff[1];
const float c = coeff[2]; const float c = coeff[2];
if (almost_zero (a)) { if (almost_zero (a)) {
auto s = solve<1> ({b, c}); auto s = roots<1> ({b, c});
return { s[0], std::numeric_limits<float>::quiet_NaN () }; return { s[0], std::numeric_limits<float>::quiet_NaN () };
} }
@ -69,7 +69,7 @@ namespace util { namespace polynomial {
namespace util { namespace polynomial { namespace util { namespace polynomial {
template <> template <>
std::array<float,3> std::array<float,3>
solve (std::array<float,4> coeffs) roots (std::array<float,4> coeffs)
{ {
const float _a = coeffs[0]; const float _a = coeffs[0];
const float _b = coeffs[1]; const float _b = coeffs[1];
@ -80,7 +80,7 @@ namespace util { namespace polynomial {
// is zero, but the benefit isn't clear given we have to merge results // is zero, but the benefit isn't clear given we have to merge results
// at the end anyway. // at the end anyway.
if (almost_zero (_a)) { if (almost_zero (_a)) {
auto s = solve<2> ({_b, _c, _d}); auto s = roots<2> ({_b, _c, _d});
return {s[0], s[1], std::numeric_limits<float>::quiet_NaN () }; return {s[0], s[1], std::numeric_limits<float>::quiet_NaN () };
} }

View File

@ -27,7 +27,7 @@ namespace util {
// first instance. // first instance.
template <size_t S> template <size_t S>
std::array<float,S> std::array<float,S>
solve (std::array<float,S+1>); roots (std::array<float,S+1>);
template <size_t S, typename T, typename U> template <size_t S, typename T, typename U>
T T

View File

@ -34,7 +34,7 @@ main (int, char**)
util::TAP::logger test; util::TAP::logger test;
for (auto &i: CUBICS) { for (auto &i: CUBICS) {
std::array<float,3> s = util::polynomial::solve<3> (i.coeffs); std::array<float,3> s = util::polynomial::roots<3> (i.coeffs);
std::sort (s.begin (), s.end ()); std::sort (s.begin (), s.end ());