Skip to content

Commit

Permalink
bezier: Possible fix for div by zero bug
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Mar 2, 2025
1 parent 49b582f commit 343316e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bezier.typ
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,9 @@
///
/// -> array Array of roots
#let _cubic-roots(a, b, c, d) = {
let epsilon = 0.000001
if calc.abs(a) < 1e-6 {
if calc.abs(b) < 1e-6 {
let epsilon = 1e-6
if calc.abs(a) < epsilon {
if calc.abs(b) < epsilon {
// Constant
if c == 0 {
return ()
Expand All @@ -554,6 +554,9 @@
let roots = (-1 * (dq + c) / (2 * b),
(dq - c) / (2 * b))
return roots.filter(t => t >= 0 - epsilon and t <= 1 + epsilon)
} else {
// No real roots
return ()
}
}

Expand Down

0 comments on commit 343316e

Please sign in to comment.