MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _quadratic_roots_in_01

Function _quadratic_roots_in_01

lib/matplotlib/bezier.py:14–40  ·  view source on GitHub ↗

Real roots of c0 + c1*x + c2*x**2 in [0, 1].

(c0, c1, c2)

Source from the content-addressed store, hash-verified

12
13
14def _quadratic_roots_in_01(c0, c1, c2):
15 """Real roots of c0 + c1*x + c2*x**2 in [0, 1]."""
16 if abs(c2) < 1e-12: # Linear
17 if abs(c1) < 1e-12:
18 return np.array([])
19 root = -c0 / c1
20 return np.array([root]) if 0 <= root <= 1 else np.array([])
21
22 disc = c1 * c1 - 4 * c2 * c0
23 if disc < 0:
24 return np.array([])
25
26 sqrt_disc = np.sqrt(disc)
27 # Numerically stable quadratic formula
28 if c1 >= 0:
29 q = -0.5 * (c1 + sqrt_disc)
30 else:
31 q = -0.5 * (c1 - sqrt_disc)
32
33 roots = []
34 if abs(q) > 1e-12:
35 roots.append(c0 / q)
36 if abs(c2) > 1e-12:
37 roots.append(q / c2)
38
39 roots = np.asarray(roots)
40 return roots[(roots >= 0) & (roots <= 1)]
41
42
43def _real_roots_in_01(coeffs):

Callers 1

_real_roots_in_01Function · 0.85

Calls 1

sqrtMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…