From 10666e85754f0117e8f8dbc0f5aa776e97f7a12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B4=A2=E4=B8=98?= Date: Fri, 5 Mar 2021 23:10:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20rect=20=E8=AE=BE=E7=BD=AEradius=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=9B=BE=E5=BD=A2=E7=94=BB=E4=B8=8D=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphic/engine/shape/rect.js | 2 +- test/unit/graphic/shape/rect-spec.js | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/graphic/engine/shape/rect.js b/src/graphic/engine/shape/rect.js index 6b8afe666..90e6b8019 100644 --- a/src/graphic/engine/shape/rect.js +++ b/src/graphic/engine/shape/rect.js @@ -59,7 +59,7 @@ class Rect extends Shape { if (!radius || !(width * height)) { context.rect(x, y, width, height); } else { - this.createRadiusPath(context, x, y, width, radius); + this.createRadiusPath(context, x, y, width, height, radius); } } diff --git a/test/unit/graphic/shape/rect-spec.js b/test/unit/graphic/shape/rect-spec.js index 1767214c0..0e415b4c2 100644 --- a/test/unit/graphic/shape/rect-spec.js +++ b/test/unit/graphic/shape/rect-spec.js @@ -10,7 +10,8 @@ describe('Rect', function() { const canvas = new Canvas({ el: 'canvas-rect', width: 200, - height: 200 + height: 200, + pixelRatio: 1 }); const rect = new Rect({ attrs: { @@ -61,15 +62,35 @@ describe('Rect', function() { y: 10, height: 20, width: 80, - radius: [ 3, 0, 5 ], + radius: [ 4, 0, 5 ], lineWidth: 1, fill: '#1890FF', strokeStyle: '#000' } }); canvas.add(rect); + + canvas.set('animateHandler', false); canvas.draw(); + + + const context = canvas.get('context'); + // 第一个image圆角区域 + const imageData1 = context.getImageData(10, 10, 1, 1).data; + // 第二个image圆角区域 + const imageData2 = context.getImageData(89, 10, 1, 1).data; + + expect(canvas.get('children').length).to.equal(1); + expect(imageData1[0]).to.equal(0); + expect(imageData1[1]).to.equal(0); + expect(imageData1[2]).to.equal(0); + expect(imageData1[3]).to.equal(0); + + expect(imageData2[0]).not.equal(0); + expect(imageData2[1]).not.equal(0); + expect(imageData2[2]).not.equal(0); + expect(imageData2[3]).not.equal(0); rect.destroy(); // document.body.removeChild(dom); });