From ebce75d4bd58011b0419ad013a82518d45affb84 Mon Sep 17 00:00:00 2001 From: zhouxinyu Date: Fri, 9 Jun 2023 16:16:56 +0800 Subject: [PATCH] fix: fix the bug of pyramid in some case --- .../fix-pyramid3d-robustness_2023-06-09-08-16.json | 10 ++++++++++ docs/demos/src/pages/pyramid3d.ts | 9 ++++++--- packages/vrender/src/graphic/pyramid3d.ts | 8 ++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 common/changes/@visactor/vrender/fix-pyramid3d-robustness_2023-06-09-08-16.json diff --git a/common/changes/@visactor/vrender/fix-pyramid3d-robustness_2023-06-09-08-16.json b/common/changes/@visactor/vrender/fix-pyramid3d-robustness_2023-06-09-08-16.json new file mode 100644 index 000000000..670549fff --- /dev/null +++ b/common/changes/@visactor/vrender/fix-pyramid3d-robustness_2023-06-09-08-16.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vrender", + "comment": "fix the bug of pyramid in some case", + "type": "patch" + } + ], + "packageName": "@visactor/vrender" +} \ No newline at end of file diff --git a/docs/demos/src/pages/pyramid3d.ts b/docs/demos/src/pages/pyramid3d.ts index c448c835c..275be0f16 100644 --- a/docs/demos/src/pages/pyramid3d.ts +++ b/docs/demos/src/pages/pyramid3d.ts @@ -24,9 +24,12 @@ function drawChartCanopus() { group.setMode('3d'); - for (let i = 5; i >= 0; i--) { - if (i === 4) { - break; + for (let i = 9; i >= 0; i--) { + // if (i === 4) { + // break; + // } + if (i < 9) { + continue; } const p3d = createPyramid3d({ points: [ diff --git a/packages/vrender/src/graphic/pyramid3d.ts b/packages/vrender/src/graphic/pyramid3d.ts index 8e7a53719..6acd5cb20 100644 --- a/packages/vrender/src/graphic/pyramid3d.ts +++ b/packages/vrender/src/graphic/pyramid3d.ts @@ -46,12 +46,16 @@ export class Pyramid3d extends Polygon implements IPyramid3d { // 找到斜率相同的两条边 const kList = points.map((p, i) => { const p1 = i === 3 ? points[0] : points[i + 1]; - return (p.y - p1.y) / (p.x - p1.x); + const dx = p.x - p1.x; + if (dx === 0) { + return 0; + } + return (p.y - p1.y) / dx; }); const pointsMap: { p: IPointLike; d: number }[] = points.map(p => ({ p, d: 0 })); let find = false; - let maxD = -Infinity; + let maxD = 0; for (let i = 0; i < kList.length - 1; i++) { for (let j = i + 1; j < kList.length; j++) { if (kList[i] === kList[j]) {