Changeset View
Changeset View
Standalone View
Standalone View
libs/global/kis_algebra_2d.cpp
Show First 20 Lines • Show All 344 Lines • ▼ Show 20 Line(s) | 312 | { | |||
---|---|---|---|---|---|
345 | return approximateRectFromPoints(resultPoints); | 345 | return approximateRectFromPoints(resultPoints); | ||
346 | } | 346 | } | ||
347 | 347 | | |||
348 | int quadraticEquation(qreal a, qreal b, qreal c, qreal *x1, qreal *x2) | 348 | int quadraticEquation(qreal a, qreal b, qreal c, qreal *x1, qreal *x2) | ||
349 | { | 349 | { | ||
350 | int numSolutions = 0; | 350 | int numSolutions = 0; | ||
351 | 351 | | |||
352 | const qreal D = pow2(b) - 4 * a * c; | 352 | const qreal D = pow2(b) - 4 * a * c; | ||
353 | const qreal eps = 1e-14; | ||||
353 | 354 | | |||
354 | if (D < 0) { | 355 | if (qAbs(D) <= eps) { | ||
355 | return 0; | | |||
356 | } else if (qFuzzyCompare(D, 0)) { | | |||
357 | *x1 = -b / (2 * a); | 356 | *x1 = -b / (2 * a); | ||
358 | numSolutions = 1; | 357 | numSolutions = 1; | ||
358 | } else if (D < 0) { | ||||
359 | return 0; | ||||
359 | } else { | 360 | } else { | ||
360 | const qreal sqrt_D = std::sqrt(D); | 361 | const qreal sqrt_D = std::sqrt(D); | ||
361 | 362 | | |||
362 | *x1 = (-b + sqrt_D) / (2 * a); | 363 | *x1 = (-b + sqrt_D) / (2 * a); | ||
363 | *x2 = (-b - sqrt_D) / (2 * a); | 364 | *x2 = (-b - sqrt_D) / (2 * a); | ||
364 | numSolutions = 2; | 365 | numSolutions = 2; | ||
365 | } | 366 | } | ||
366 | 367 | | |||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |