Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bezier: Fix root precision bug #388

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/bezier.typ
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
///
/// -> 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 {
// Constant
Expand All @@ -502,7 +503,7 @@

// Linear
let root = -1 * d / c
if root < 0 and root > 1 {
if root < 0 - epsilon and root > 1 + epsilon {
return ()
}
return (root,)
Expand All @@ -514,7 +515,7 @@
dq = calc.sqrt(dq)
let roots = (-1 * (dq + c) / (2 * b),
(dq - c) / (2 * b))
return roots.filter(t => t >= 0 and t <= 1)
return roots.filter(t => t >= 0 - epsilon and t <= 1 + epsilon)
}
}

Expand Down Expand Up @@ -543,7 +544,7 @@
qq * calc.cos((th + 4 * calc.pi) / 3) + aa)
}

return roots.filter(t => t >= 0 and t <= 1)
return roots.filter(t => t >= 0 - epsilon and t <= 1 + epsilon)
}

/// Calculate 2D cubic-bezier and line intersetction points
Expand Down