bezierjs
bezierjs copied to clipboard
function "getABC()" has potential for divide by 0 error
I was looking through the codebase, and it looks like this function has the potential for a divide by 0 error if s
is 0.
function getABC(n, S, B, E, t) {
if (typeof t === "undefined") {
t = 0.5;
}
var u = utils.projectionratio(t, n),
um = 1 - u,
C = {
x: u * S.x + um * E.x,
y: u * S.y + um * E.y
},
s = utils.abcratio(t, n),
A = {
x: B.x + (B.x - C.x) / s,
y: B.y + (B.y - C.y) / s
};
return { A: A, B: B, C: C };
}
If we're code hunting: while true, can you find an actual curve (or set of curves) for which this would actually happen?
Looking at utils.abcratio
, I see it returns t
if t === 0
, so this function would error if you ever pass it 0 for t.
As an isolated case that'd be ridiculous, but as part of a loop/map that could certainly happen. Adding t=0 and t=1 shortcuts is a good idea.