From 22909c95dbcb7eef28c4efd48f8c52218808ae1b Mon Sep 17 00:00:00 2001 From: xile611 Date: Fri, 20 Sep 2024 14:11:16 +0800 Subject: [PATCH 1/2] fix: fix path string of arc, fix #1434 --- packages/vrender-core/src/common/shape/arc.ts | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/packages/vrender-core/src/common/shape/arc.ts b/packages/vrender-core/src/common/shape/arc.ts index 6fc003e22..2c6d36924 100644 --- a/packages/vrender-core/src/common/shape/arc.ts +++ b/packages/vrender-core/src/common/shape/arc.ts @@ -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 + ); + } }; From 26d0c9769df7aa2f9bc7d878de99eb9feb9f33ae Mon Sep 17 00:00:00 2001 From: xile611 Date: Fri, 20 Sep 2024 14:11:59 +0800 Subject: [PATCH 2/2] docs: update changlog of rush --- .../fix-custom-path-arc-string_2024-09-20-06-11.json | 11 +++++++++++ .../fix-custom-path-arc-string_2024-09-20-06-11.json | 11 +++++++++++ .../fix-custom-path-arc-string_2024-09-20-06-11.json | 11 +++++++++++ .../fix-custom-path-arc-string_2024-09-20-06-11.json | 11 +++++++++++ .../fix-custom-path-arc-string_2024-09-20-06-11.json | 11 +++++++++++ .../fix-custom-path-arc-string_2024-09-20-06-11.json | 11 +++++++++++ 6 files changed, 66 insertions(+) create mode 100644 common/changes/@visactor/react-vrender-utils/fix-custom-path-arc-string_2024-09-20-06-11.json create mode 100644 common/changes/@visactor/react-vrender/fix-custom-path-arc-string_2024-09-20-06-11.json create mode 100644 common/changes/@visactor/vrender-components/fix-custom-path-arc-string_2024-09-20-06-11.json create mode 100644 common/changes/@visactor/vrender-core/fix-custom-path-arc-string_2024-09-20-06-11.json create mode 100644 common/changes/@visactor/vrender-kits/fix-custom-path-arc-string_2024-09-20-06-11.json create mode 100644 common/changes/@visactor/vrender/fix-custom-path-arc-string_2024-09-20-06-11.json diff --git a/common/changes/@visactor/react-vrender-utils/fix-custom-path-arc-string_2024-09-20-06-11.json b/common/changes/@visactor/react-vrender-utils/fix-custom-path-arc-string_2024-09-20-06-11.json new file mode 100644 index 000000000..81cbe0710 --- /dev/null +++ b/common/changes/@visactor/react-vrender-utils/fix-custom-path-arc-string_2024-09-20-06-11.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@visactor/react-vrender/fix-custom-path-arc-string_2024-09-20-06-11.json b/common/changes/@visactor/react-vrender/fix-custom-path-arc-string_2024-09-20-06-11.json new file mode 100644 index 000000000..c9402d7a5 --- /dev/null +++ b/common/changes/@visactor/react-vrender/fix-custom-path-arc-string_2024-09-20-06-11.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@visactor/vrender-components/fix-custom-path-arc-string_2024-09-20-06-11.json b/common/changes/@visactor/vrender-components/fix-custom-path-arc-string_2024-09-20-06-11.json new file mode 100644 index 000000000..99981ca6a --- /dev/null +++ b/common/changes/@visactor/vrender-components/fix-custom-path-arc-string_2024-09-20-06-11.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@visactor/vrender-core/fix-custom-path-arc-string_2024-09-20-06-11.json b/common/changes/@visactor/vrender-core/fix-custom-path-arc-string_2024-09-20-06-11.json new file mode 100644 index 000000000..e57e4e231 --- /dev/null +++ b/common/changes/@visactor/vrender-core/fix-custom-path-arc-string_2024-09-20-06-11.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@visactor/vrender-kits/fix-custom-path-arc-string_2024-09-20-06-11.json b/common/changes/@visactor/vrender-kits/fix-custom-path-arc-string_2024-09-20-06-11.json new file mode 100644 index 000000000..6ad2d9e4c --- /dev/null +++ b/common/changes/@visactor/vrender-kits/fix-custom-path-arc-string_2024-09-20-06-11.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@visactor/vrender/fix-custom-path-arc-string_2024-09-20-06-11.json b/common/changes/@visactor/vrender/fix-custom-path-arc-string_2024-09-20-06-11.json new file mode 100644 index 000000000..332c40890 --- /dev/null +++ b/common/changes/@visactor/vrender/fix-custom-path-arc-string_2024-09-20-06-11.json @@ -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" +} \ No newline at end of file