Skip to content

Commit

Permalink
Merge pull request #1452 from VisActor/fix/custom-path-arc-string
Browse files Browse the repository at this point in the history
Fix/custom path arc string
  • Loading branch information
xile611 authored Sep 20, 2024
2 parents 786521e + 26d0c97 commit 0d39ef6
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix path string of arc, fix #1434\n\n",
"type": "none",
"packageName": "@visactor/react-vrender-utils"
}
],
"packageName": "@visactor/react-vrender-utils",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix path string of arc, fix #1434\n\n",
"type": "none",
"packageName": "@visactor/react-vrender"
}
],
"packageName": "@visactor/react-vrender",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix path string of arc, fix #1434\n\n",
"type": "none",
"packageName": "@visactor/vrender-components"
}
],
"packageName": "@visactor/vrender-components",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix path string of arc, fix #1434\n\n",
"type": "none",
"packageName": "@visactor/vrender-core"
}
],
"packageName": "@visactor/vrender-core",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix path string of arc, fix #1434\n\n",
"type": "none",
"packageName": "@visactor/vrender-kits"
}
],
"packageName": "@visactor/vrender-kits",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix path string of arc, fix #1434\n\n",
"type": "none",
"packageName": "@visactor/vrender"
}
],
"packageName": "@visactor/vrender",
"email": "dingling112@gmail.com"
}
59 changes: 33 additions & 26 deletions packages/vrender-core/src/common/shape/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,30 +184,37 @@ export const addArcToBezierPath = (
) => {
// https://stackoverflow.com/questions/1734745/how-to-create-circle-with-b%C3%A9zier-curves
const delta = Math.abs(endAngle - startAngle);
const len = (Math.tan(delta / 4) * 4) / 3;
const dir = endAngle < startAngle ? -1 : 1;

const c1 = Math.cos(startAngle);
const s1 = Math.sin(startAngle);
const c2 = Math.cos(endAngle);
const s2 = Math.sin(endAngle);

const x1 = c1 * rx + cx;
const y1 = s1 * ry + cy;

const x4 = c2 * rx + cx;
const y4 = s2 * ry + cy;

const hx = rx * len * dir;
const hy = ry * len * dir;

bezierPath.push(
// Move control points on tangent.
x1 - hx * s1,
y1 + hy * c1,
x4 + hx * s2,
y4 - hy * c2,
x4,
y4
);
const count = delta > 0.5 * Math.PI ? Math.ceil((2 * delta) / Math.PI) : 1;
const stepAngle = (endAngle - startAngle) / count;

for (let i = 0; i < count; i++) {
const sa = startAngle + stepAngle * i;
const ea = startAngle + stepAngle * (i + 1);
const len = (Math.tan(Math.abs(stepAngle) / 4) * 4) / 3;
const dir = ea < sa ? -1 : 1;

const c1 = Math.cos(sa);
const s1 = Math.sin(sa);
const c2 = Math.cos(ea);
const s2 = Math.sin(ea);

const x1 = c1 * rx + cx;
const y1 = s1 * ry + cy;

const x4 = c2 * rx + cx;
const y4 = s2 * ry + cy;

const hx = rx * len * dir;
const hy = ry * len * dir;

bezierPath.push(
// Move control points on tangent.
x1 - hx * s1,
y1 + hy * c1,
x4 + hx * s2,
y4 - hy * c2,
x4,
y4
);
}
};

0 comments on commit 0d39ef6

Please sign in to comment.