mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-08 14:58:06 +02:00
[_cairo_spline_bound] Fix the check for feasible solutions
Also make it more strict. The only times we call sqrt now is when a solution in (0,1) exists.
This commit is contained in:
parent
7f840d156c
commit
3bf1b7d574
1 changed files with 6 additions and 3 deletions
|
|
@ -277,15 +277,18 @@ _cairo_spline_bound (cairo_spline_add_point_func_t add_point_func,
|
|||
double b2 = b * b; \
|
||||
double delta = b2 - a * c; \
|
||||
if (delta > 0) { \
|
||||
double a2 = a * a; \
|
||||
double ab = a * b; \
|
||||
double a2_b2 = a * a + b2; \
|
||||
double _2ab = 2 * a * b; \
|
||||
double _b_a = - b / a; \
|
||||
/* We are only interested in solutions t that satisfy 0<t<1 \
|
||||
* here. We do some checks to avoid sqrt if the solutions \
|
||||
* are not in that range. The checks can be derived from: \
|
||||
* \
|
||||
* 0 < (-b±√delta)/a < 1 \
|
||||
*/ \
|
||||
if (delta > (ab >= 0 ? b2 : a2 + b2 + 2*ab)) { \
|
||||
if ((_2ab >= 0 && delta > b2 && delta < a2_b2 - _2ab) || \
|
||||
(_2ab < 0 && ((_b_a>=1 && (delta < b2 && delta > a2_b2 + _2ab)) || \
|
||||
(_b_a< 1 && (delta < b2 || delta < a2_b2 + _2ab))))) { \
|
||||
double sqrt_delta = sqrt (delta); \
|
||||
ADD ((-b - sqrt_delta) / a); \
|
||||
ADD ((-b + sqrt_delta) / a); \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue