22 #include "../../include/ecl/geometry/polynomial.hpp" 
   37         b = p.coefficients()[1] + factor*a;
 
   39         f.coefficients() << b, a;
 
   40         remainder = p.coefficients()[0]+factor*b;
 
   65                 intercepts << -1.0*b/a;
 
   71         Array<double> intercepts;
 
   72         double a = p.coefficients()[2];
 
   73         double b = p.coefficients()[1];
 
   74         double c = p.coefficients()[0];
 
   77                 f.coefficients() << c, b;
 
   80                 double discriminant = b*b - 4*a*c;
 
   81                 if ( discriminant > 0.0 ) {
 
   83                         intercepts << (-b + sqrt(discriminant))/(2*a), (-b - sqrt(discriminant))/(2*a);
 
   84                 } 
else if ( discriminant == 0.0 ) {
 
   86                         intercepts << -b/(2*a);
 
   94         Array<double> intercepts;
 
   95         double a = polynomial.coefficients()[3];
 
   96         double b = polynomial.coefficients()[2];
 
   97         double c = polynomial.coefficients()[1];
 
   98         double d = polynomial.coefficients()[0];
 
  108         double p = (3*a*c - b*b)/(3*a*a);
 
  109         double q = (2*b*b*b - 9*a*b*c + 27*a*a*d)/(27*a*a*a);
 
  110         double discriminant = p*p*p/27 + q*q/4;
 
  114         double shift = -b/(3*a);
 
  115         if ( ( p == 0 ) && ( q == 0 ) ) {
 
  117                 intercepts.resize(1);
 
  120         } 
else if ( p == 0 ) { 
 
  123                 intercepts.resize(1);
 
  125         } 
else if ( q == 0 ) {
 
  128                 intercepts.resize(3);
 
  129                 intercepts << shift, sqrt(-1*p) + shift, -sqrt(-1*p) + shift;
 
  130         } 
else if ( discriminant == 0 ) { 
 
  133                 intercepts.resize(2);
 
  134                 intercepts << 3*q/p + shift, (-3*q)/(2*p) + shift;
 
  135         } 
else if ( discriminant >= 0 ) {
 
  139                 intercepts.resize(1);
 
  140                 intercepts << u + v + shift;
 
  145                 double t_1 = 2.0*sqrt(-p/3.0)*cos((1.0/3.0)*acos( ((3.0*q)/(2.0*p)) * sqrt(-3.0/p)));
 
  146                 double t_2 = 2.0*sqrt(-p/3.0)*cos((1.0/3.0)*acos(( (3.0*q)/(2.0*p)) * sqrt(-3.0/p))-(2.0*
ecl::pi)/3.0);
 
  147                 double t_3 = 2.0*sqrt(-p/3.0)*cos((1.0/3.0)*acos(( (3.0*q)/(2.0*p)) * sqrt(-3.0/p))-(4.0*
ecl::pi)/3.0);
 
  148                 intercepts.resize(3);
 
  149                 intercepts << t_1+shift, t_2+shift, t_3+shift;
 
  156         double a_0 = 
f.coefficients()[0];
 
  157         double b_0 = 
f.coefficients()[1];
 
  158         double a_1 = g.coefficients()[0];
 
  159         double b_1 = g.coefficients()[1];
 
  161                 last_operation_failed = 
true;
 
  164                 point.x((a_0 - a_1)/(b_1 - b_0));
 
  165                 point.y(
f(point.x()));
 
  171         const double& x_begin, 
const double& x_end, 
const LinearFunction &
function) {
 
  172     double max = 
function(x_begin);
 
  173     double test_max = 
function(x_end);
 
  174     if ( test_max > max ) {
 
  181         const double& x_begin, 
const double& x_end, 
const CubicPolynomial& cubic) {
 
  183     double max = cubic(x_begin);
 
  184     double test_max = cubic(x_end);
 
  185     if ( test_max > max ) {
 
  189     double a = 3*coefficients[3];
 
  190     double b = 2*coefficients[2];
 
  191     double c = coefficients[1];
 
  194                 if ( ( root > x_begin ) && ( root < x_end ) ) {
 
  195                         test_max = cubic(root);
 
  196                         if ( test_max > max ) {
 
  201                 double sqrt_term = b*b-4*a*c;
 
  202                 if ( sqrt_term > 0 ) {
 
  203                         double root = ( -b + sqrt(b*b-4*a*c))/(2*a);
 
  204                         if ( ( root > x_begin ) && ( root < x_end ) ) {
 
  205                                 test_max = cubic(root);
 
  206                                 if ( test_max > max ) {
 
  210                         root = ( -b - sqrt(b*b-4*a*c))/(2*a);
 
  211                         if ( ( root > x_begin ) && ( root < x_end ) ) {
 
  212                                 test_max = cubic(root);
 
  213                                 if ( test_max > max ) {
 
  223         const double& x_begin, 
const double& x_end, 
const LinearFunction &
function) {
 
  224     double min = 
function(x_begin);
 
  225     double test_min = 
function(x_end);
 
  226     if ( test_min < min ) {
 
  233         const double& x_begin, 
const double& x_end, 
const CubicPolynomial& cubic) {
 
  235     double min = cubic(x_begin);
 
  236     double test_min = cubic(x_end);
 
  237     if ( test_min < min ) {
 
  241     double a = 3*coefficients[3];
 
  242     double b = 2*coefficients[2];
 
  243     double c = coefficients[1];
 
  246                 if ( ( root > x_begin ) && ( root < x_end ) ) {
 
  247                         test_min = cubic(root);
 
  248                         if ( test_min < min ) {
 
  253                 double sqrt_term = b*b-4*a*c;
 
  254                 if ( sqrt_term > 0 ) {
 
  255                         double root = ( -b + sqrt(b*b-4*a*c))/(2*a);
 
  256                         if ( ( root > x_begin ) && ( root < x_end ) ) {
 
  257                                 test_min = cubic(root);
 
  258                                 if ( test_min < min ) {
 
  262                         root = ( -b - sqrt(b*b-4*a*c))/(2*a);
 
  263                         if ( ( root > x_begin ) && ( root < x_end ) ) {
 
  264                                 test_min = cubic(root);
 
  265                                 if ( test_min < min ) {