linebender/spline

missing term in equation?

notwa opened this issue · 2 comments

notwa commented

I was snooping through the code and I found something peculiar.

spline/src/hyperbezier.rs

Lines 261 to 263 in e4718e9

let a = (bias - 1.0).min(MAX_A);
let norm = 1.0 / (1.0 - a) + (1.0 - a).ln() - 1.0;
(1.0 / (1.0 - a * s) + (1.0 - a * s).ln()) / norm

it may be that it doesn't matter in the context of compute_theta, but when bias ≥ 1.0002, integrate_basis has a huge y-offset for smaller values of bias. for instance, integrate_basis(1.0002, 0.0) = 49986667.306. I believe the numerator is missing a -1 term, like so:

    (1.0 / (1.0 - a * s) + (1.0 - a * s).ln() - 1.0) / norm

Good catch! From a mathematical point of view, it doesn't matter because only the definite integral is computed (any integration constant is subtracted out). But because these values can get large, it reduces precision, so adding your term would be an improvement.

I'll happily take a PR, or fold this into another commit as I continue work.

notwa commented

nah, you should just commit this yourself.