Skip to content

Commit c7b555a

Browse files
committed
Internal lib - Improve smooth path generation
1 parent a4932ac commit c7b555a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/lib.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,8 @@ export function createSmoothPath(points) {
756756
if (slopes[i - 1] * slopes[i] <= 0) {
757757
tangents[i] = 0;
758758
} else {
759-
const commonSlope = (slopes[i - 1] + slopes[i]) / 2;
760-
tangents[i] = Math.min(Math.abs(commonSlope), Math.abs(slopes[i - 1]), Math.abs(slopes[i])) * Math.sign(commonSlope);
759+
const harmonicMean = (2 * slopes[i - 1] * slopes[i]) / (slopes[i - 1] + slopes[i]);
760+
tangents[i] = harmonicMean;
761761
}
762762
}
763763

@@ -766,10 +766,8 @@ export function createSmoothPath(points) {
766766
const y1 = points[i].y;
767767
const x2 = points[i + 1].x;
768768
const y2 = points[i + 1].y;
769-
770769
const m1 = tangents[i];
771770
const m2 = tangents[i + 1];
772-
773771
const controlX1 = x1 + (x2 - x1) / 3;
774772
const controlY1 = y1 + m1 * (x2 - x1) / 3;
775773
const controlX2 = x2 - (x2 - x1) / 3;
@@ -781,6 +779,7 @@ export function createSmoothPath(points) {
781779
return path.join(' ');
782780
}
783781

782+
784783
export function createUid() {
785784
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
786785
.replace(/[xy]/g, function (c) {

0 commit comments

Comments
 (0)