Skip to content

Commit c78b250

Browse files
committed
Internal lib - Improve smooth path generation
1 parent 4d753fe commit c78b250

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ export function createSmoothPath(points) {
748748
dy[i] = points[i + 1].y - points[i].y;
749749
slopes[i] = dy[i] / dx[i];
750750
}
751+
751752
tangents[0] = slopes[0];
752753
tangents[n] = slopes[n - 1];
753754

@@ -756,7 +757,7 @@ export function createSmoothPath(points) {
756757
tangents[i] = 0;
757758
} else {
758759
const commonSlope = (slopes[i - 1] + slopes[i]) / 2;
759-
tangents[i] = commonSlope;
760+
tangents[i] = Math.min(Math.abs(commonSlope), Math.abs(slopes[i - 1]), Math.abs(slopes[i])) * Math.sign(commonSlope);
760761
}
761762
}
762763

@@ -776,6 +777,7 @@ export function createSmoothPath(points) {
776777

777778
path.push(`C ${checkNaN(controlX1)},${checkNaN(controlY1)} ${checkNaN(controlX2)},${checkNaN(controlY2)} ${checkNaN(x2)},${checkNaN(y2)}`);
778779
}
780+
779781
return path.join(' ');
780782
}
781783

0 commit comments

Comments
 (0)