From 7a764f08ad72baaf1f8d639dac35d9e632ee9c0b Mon Sep 17 00:00:00 2001 From: plainheart Date: Wed, 19 Jan 2022 16:37:53 +0800 Subject: [PATCH] fix(sector): fix some broken cases caused by precision. --- src/graphic/helper/roundSector.ts | 4 +-- test/sector.html | 46 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/graphic/helper/roundSector.ts b/src/graphic/helper/roundSector.ts index 1c2099214..7a09f2c90 100644 --- a/src/graphic/helper/roundSector.ts +++ b/src/graphic/helper/roundSector.ts @@ -149,8 +149,8 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: { const { startAngle, endAngle, cx, cy, cornerRadius } = shape; let arc = mathAbs(endAngle - startAngle); - const mod = arc && arc % PI2; - mod && (arc = mod); + const mod = arc > PI2 && arc % PI2; + mod > e && (arc = mod); // is a point if (!(radius > e)) { diff --git a/test/sector.html b/test/sector.html index 828c096c5..bc2510151 100644 --- a/test/sector.html +++ b/test/sector.html @@ -101,6 +101,7 @@ } })); + // should be collapsed to a line zr.add(new zrender.Sector({ position: [100, 300], scale: [1, 1], @@ -174,6 +175,51 @@ cornerRadius: [0, 0, 35, 20] } })); + + // should be a circle + zr.add(new zrender.Sector({ + position: [650, 100], + scale: [1, 1], + style: { + stroke: 'black' + }, + shape: { + startAngle: -1.570796326794896, + endAngle: 4.712388980384691, + r: 100, + // clockwise: false + } + })); + + // should be collapsed to a line + zr.add(new zrender.Sector({ + position: [650, 250], + scale: [1, 1], + style: { + stroke: 'black' + }, + shape: { + startAngle: 1.0001, + endAngle: 1, + r: 100, + // clockwise: false + } + })); + + // should be nearly a circle + zr.add(new zrender.Sector({ + position: [650, 500], + scale: [1, 1], + style: { + stroke: 'black' + }, + shape: { + startAngle: 1.0002, + endAngle: 1, + r: 100, + // clockwise: false + } + }));