Permalink
Browse files

Fix a bug in cardinal-closed interpolation.

  • Loading branch information...
1 parent ca3585e commit 9f71e4e211dd29cdd77212ba05004a28fcbc152c @mbostock mbostock committed Apr 11, 2011
Showing with 22 additions and 25 deletions.
  1. +7 −8 d3.js
  2. +2 −2 d3.min.js
  3. +4 −5 examples/force/cluster.html
  4. +1 −1 src/core/core.js
  5. +6 −7 src/svg/line.js
  6. +1 −1 tests/test-svg-area.out
  7. +1 −1 tests/test-svg-line.out
View
15 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.10.0"}; // semver
+(function(){d3 = {version: "1.10.1"}; // semver
if (!Date.now) Date.now = function() {
return +new Date();
};
@@ -2563,7 +2563,7 @@ function d3_svg_lineStepAfter(points) {
function d3_svg_lineCardinalClosed(points, tension) {
return points.length < 3
? d3_svg_lineLinear(points)
- : points[0] + d3_svg_lineHermite(points,
+ : points[0] + d3_svg_lineHermite((points.push(points[0]), points),
d3_svg_lineCardinalTangents([points[points.length - 2]]
.concat(points, [points[1]]), tension));
}
@@ -2627,18 +2627,17 @@ function d3_svg_lineHermite(points, tangents) {
function d3_svg_lineCardinalTangents(points, tension) {
var tangents = [],
a = (1 - tension) / 2,
- p0 = points[0],
- p1 = points[1],
- p2 = points[2],
- i = 2,
+ p0,
+ p1 = points[0],
+ p2 = points[1],
+ i = 1,
n = points.length;
while (++i < n) {
- tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
p0 = p1;
p1 = p2;
p2 = points[i];
+ tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
}
- tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
return tangents;
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -19,11 +19,12 @@
}
path.hull {
fill: lightsteelblue;
- opacity: 0.3;
+ fill-opacity: 0.3;
}
line.link {
stroke: #333;
- opacity: 0.5;
+ stroke-opacity: 0.5;
+ pointer-events: none;
}
</style>
</head>
@@ -144,9 +145,7 @@
// create convex hulls
var hulls = [];
for (i in h) {
- var p = d3.geom.hull(h[i]);
- p.push(p[0]); // close the loop
- hulls.push({group: i, path: p});
+ hulls.push({group: i, path: d3.geom.hull(h[i])});
}
return hulls;
View
@@ -1 +1 @@
-d3 = {version: "1.10.0"}; // semver
+d3 = {version: "1.10.1"}; // semver
View
@@ -121,7 +121,7 @@ function d3_svg_lineStepAfter(points) {
function d3_svg_lineCardinalClosed(points, tension) {
return points.length < 3
? d3_svg_lineLinear(points)
- : points[0] + d3_svg_lineHermite(points,
+ : points[0] + d3_svg_lineHermite((points.push(points[0]), points),
d3_svg_lineCardinalTangents([points[points.length - 2]]
.concat(points, [points[1]]), tension));
}
@@ -185,18 +185,17 @@ function d3_svg_lineHermite(points, tangents) {
function d3_svg_lineCardinalTangents(points, tension) {
var tangents = [],
a = (1 - tension) / 2,
- p0 = points[0],
- p1 = points[1],
- p2 = points[2],
- i = 2,
+ p0,
+ p1 = points[0],
+ p2 = points[1],
+ i = 1,
n = points.length;
while (++i < n) {
- tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
p0 = p1;
p1 = p2;
p2 = points[i];
+ tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
}
- tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]);
return tangents;
}
View
@@ -46,5 +46,5 @@ interpolate(cardinal):
interpolate(cardinal-closed):
[[0, 0]]: M0,0L0,0Z
[[0, 0], [5, 5]]: M0,0L5,5L5,0L0,0Z
- [[0, 0], [5, 5], [10, 0]]: M0,0C0,0,3.5,5,5,5S10,0,10,0L10,0C10,0,6.5,0,5,0S0,0,0,0Z
+ [[0, 0], [5, 5], [10, 0]]: M0,0C-0.7500000000000001,0.7500000000000001,3.5,5,5,5S10.75,0.7500000000000001,10,0S0.7500000000000001,-0.7500000000000001,0,0L10,0C10.75,0,6.5,0,5,0S-0.7500000000000001,0,0,0S9.25,0,10,0Z
View
@@ -41,5 +41,5 @@ interpolate(cardinal):
interpolate(cardinal-closed):
[[0, 0]]: M0,0
[[0, 0], [5, 5]]: M0,0L5,5
- [[0, 0], [5, 5], [10, 0]]: M0,0C0,0,3.5,5,5,5S10,0,10,0
+ [[0, 0], [5, 5], [10, 0]]: M0,0C-0.7500000000000001,0.7500000000000001,3.5,5,5,5S10.75,0.7500000000000001,10,0S0.7500000000000001,-0.7500000000000001,0,0

0 comments on commit 9f71e4e

Please sign in to comment.