diff --git a/uppsrc/Core/Util.h b/uppsrc/Core/Util.h index 5668a94ec..d8f8693d2 100644 --- a/uppsrc/Core/Util.h +++ b/uppsrc/Core/Util.h @@ -292,6 +292,8 @@ double roundr (double d, int digits); double floorr (double d, int digits); double ceilr (double d, int digits); +int SolveQuadraticEquation(double A, double B, double C, double *r); + //BW - use max //inline double fmax(double x, double y) { return x >= y ? x : y; } //BW - use min diff --git a/uppsrc/Core/mathutil.cpp b/uppsrc/Core/mathutil.cpp index d934cf762..5d328bc16 100644 --- a/uppsrc/Core/mathutil.cpp +++ b/uppsrc/Core/mathutil.cpp @@ -233,4 +233,32 @@ double ceilr(double d, int digits) return ceil(d / fac) * fac; } +int SolveQuadraticEquation(double a, double b, double c, double *r) +{ + if(a == 0) { + if(b == 0) + return 0; + r[0] = r[1] = -c / b; + return 1; + } + double d = b * b - 4 * a * c; + if (d < 0) + return 0; + a *= 2; + if (d == 0) { + r[0] = r[1] = -b / a; + return 1; + } + d = sqrt(d); + if(b == 0) { + r[0] = d / a; + r[1] = -r[0]; + } + else { + r[0] = (-b + d) / a; + r[1] = (-b - d) / a; + } + return 2; +} + } diff --git a/uppsrc/Core/src.tpp/MathUtil_en-us.tpp b/uppsrc/Core/src.tpp/MathUtil_en-us.tpp index dc46720c3..54c8e945d 100644 --- a/uppsrc/Core/src.tpp/MathUtil_en-us.tpp +++ b/uppsrc/Core/src.tpp/MathUtil_en-us.tpp @@ -223,32 +223,12 @@ numerator:&] [s2;%% remainder `= numerator `- quotient `* denominator.&] [s3;%% &] [s4; &] -[s5;:ilog10`(double`): [@(0.0.255) int]_[* ilog10]_([@(0.0.255) double]_[*@3 d])&] -[s2;%% [%-*@3 d].&] -[s3;%% &] -[s4; &] -[s5;:ipow10`(int`): [@(0.0.255) double]_[* ipow10]_([@(0.0.255) int]_[*@3 i])&] -[s2;%% [%-*@3 i].&] -[s3;%% &] -[s4; &] -[s5;:normalize`(double`,int`&`): [@(0.0.255) double]_[* normalize]_([@(0.0.255) double]_[*@3 d -], [@(0.0.255) int`&]_[*@3 exponent])&] -[s2;%% [%-*@3 d] [%-*@3 exponent].&] -[s3;%% &] -[s4; &] -[s5;:roundr`(double`,int`): [@(0.0.255) double]_[* roundr]_([@(0.0.255) double]_[*@3 d], -[@(0.0.255) int]_[*@3 digits])&] -[s2;%% [%-*@3 d] [%-*@3 digits].&] -[s3;%% &] -[s4; &] -[s5;:floorr`(double`,int`): [@(0.0.255) double]_[* floorr]_([@(0.0.255) double]_[*@3 d], -[@(0.0.255) int]_[*@3 digits])&] -[s2;%% [%-*@3 d] [%-*@3 digits].&] -[s3;%% &] -[s4; &] -[s5;:ceilr`(double`,int`): [@(0.0.255) double]_[* ceilr]_([@(0.0.255) double]_[*@3 d], -[@(0.0.255) int]_[*@3 digits])&] -[s2;%% [%-*@3 d] [%-*@3 digits].&] +[s5;:Upp`:`:SolveQuadraticEquation`(double`,double`,double`,double`*`): [@(0.0.255) int +]_[* SolveQuadraticEquation]([@(0.0.255) double]_[*@3 A], [@(0.0.255) double]_[*@3 B], +[@(0.0.255) double]_[*@3 C], [@(0.0.255) double]_`*[*@3 r])&] +[s2;%% Solves quadratic equation. Returns number of solutions (0, +1 or 2), stores solutions to array r (which must have at least +two elements).&] [s3;%% &] [s4; &] [s5;:AsString`(double`,int`): [_^topic`:`/`/Core`/src`/String`$en`-us`#String`:`:class^ S diff --git a/uppsrc/Painter/SvgBounds.cpp b/uppsrc/Painter/SvgBounds.cpp index 5f38050fb..8f1df341d 100644 --- a/uppsrc/Painter/SvgBounds.cpp +++ b/uppsrc/Painter/SvgBounds.cpp @@ -69,34 +69,6 @@ void BoundsPainter::QuadraticOp(const Pointf& p, bool) QuadraticOp(2.0 * current - qcontrol, p, false); } -int SolveQuadraticEquation(double a, double b, double c, double *r) -{ - if(a == 0) { - if(b == 0) - return 0; - r[0] = r[1] = -c / b; - return 1; - } - double d = b * b - 4 * a * c; - if (d < 0) - return 0; - a *= 2; - if (d == 0) { - r[0] = r[1] = -b / a; - return 1; - } - d = sqrt(d); - if(b == 0) { - r[0] = d / a; - r[1] = -r[0]; - } - else { - r[0] = (-b + d) / a; - r[1] = (-b - d) / a; - } - return 2; -} - void CubicMinMax(double p1, double p2, double p3, double p4, double& l, double& h) { double c0 = 3 * (p2 - p1); double c1 = 6 * (p3 - p2);