Skip to content

Commit af88c35

Browse files
committed
Use linear segments for basis interpolation ends.
The first and last segment of a line interpolated using basis (B-spline) interpolation are necessarily linear. WebKit appears to have a bug where linear Bézier segments do not compute tangents correctly (presumably because the control points are coincident with an end point, and the angle of a zero-length vector is undefined). We can workaround this browser bug by using linear segments for the start and end.
1 parent 747c523 commit af88c35

3 files changed

Lines changed: 11 additions & 21 deletions

File tree

d3.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,24 +4079,18 @@ d3 = function() {
40794079
}
40804080
function d3_svg_lineBasis(points) {
40814081
if (points.length < 3) return d3_svg_lineLinear(points);
4082-
var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0 ];
4083-
d3_svg_lineBasisBezier(path, px, py);
4084-
while (++i < n) {
4082+
var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
4083+
points.push(points[n - 1]);
4084+
while (++i <= n) {
40854085
pi = points[i];
40864086
px.shift();
40874087
px.push(pi[0]);
40884088
py.shift();
40894089
py.push(pi[1]);
40904090
d3_svg_lineBasisBezier(path, px, py);
40914091
}
4092-
i = -1;
4093-
while (++i < 2) {
4094-
px.shift();
4095-
px.push(pi[0]);
4096-
py.shift();
4097-
py.push(pi[1]);
4098-
d3_svg_lineBasisBezier(path, px, py);
4099-
}
4092+
points.pop();
4093+
path.push("L", pi);
41004094
return path.join("");
41014095
}
41024096
function d3_svg_lineBasisOpen(points) {

0 commit comments

Comments
 (0)