| 7 | namespace msdfgen { |
| 8 | |
| 9 | int solveQuadratic(double x[2], double a, double b, double c) { |
| 10 | // a == 0 -> linear equation |
| 11 | if (a == 0 || fabs(b) > 1e12*fabs(a)) { |
| 12 | // a == 0, b == 0 -> no solution |
| 13 | if (b == 0) { |
| 14 | if (c == 0) |
| 15 | return -1; // 0 == 0 |
| 16 | return 0; |
| 17 | } |
| 18 | x[0] = -c/b; |
| 19 | return 1; |
| 20 | } |
| 21 | double dscr = b*b-4*a*c; |
| 22 | if (dscr > 0) { |
| 23 | dscr = sqrt(dscr); |
| 24 | x[0] = (-b+dscr)/(2*a); |
| 25 | x[1] = (-b-dscr)/(2*a); |
| 26 | return 2; |
| 27 | } else if (dscr == 0) { |
| 28 | x[0] = -b/(2*a); |
| 29 | return 1; |
| 30 | } else |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int solveCubicNormed(double x[3], double a, double b, double c) { |
| 35 | double a2 = a*a; |
no outgoing calls
no test coverage detected