mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core, Painter: SolveQuadraticEquation moved to Core/Util.h
git-svn-id: svn://ultimatepp.org/upp/trunk@14750 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5ca2c77339
commit
d4cf630a1c
4 changed files with 36 additions and 54 deletions
|
|
@ -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<double>
|
||||
//inline double fmax(double x, double y) { return x >= y ? x : y; }
|
||||
//BW - use min<double>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue