From 3bcc5cdd3cf5aa9abdbef59cfe4f9c41dbe12ae8 Mon Sep 17 00:00:00 2001 From: xiaoiver Date: Sun, 26 Jan 2025 16:43:16 +0800 Subject: [PATCH] chore: tolerate max error in rough test cases --- __tests__/ssr/rough-circle.spec.ts | 15 +++++++++++++++ __tests__/ssr/rough-ellipse.spec.ts | 3 +++ __tests__/ssr/rough-path.spec.ts | 6 ++++++ __tests__/ssr/rough-polyline.spec.ts | 3 +++ __tests__/ssr/rough-rect.spec.ts | 12 ++++++++++++ packages/site/docs/index.md | 16 ++++++++++++++++ packages/site/docs/zh/index.md | 16 ++++++++++++++++ 7 files changed, 71 insertions(+) diff --git a/__tests__/ssr/rough-circle.spec.ts b/__tests__/ssr/rough-circle.spec.ts index d65eec5..90a4cb8 100644 --- a/__tests__/ssr/rough-circle.spec.ts +++ b/__tests__/ssr/rough-circle.spec.ts @@ -43,6 +43,9 @@ describe('RoughCircle', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-circle', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -66,6 +69,9 @@ describe('RoughCircle', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-circle-zigzag', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -90,6 +96,9 @@ describe('RoughCircle', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-circle-cross-hatch', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -111,6 +120,9 @@ describe('RoughCircle', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-circle-solid', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -132,6 +144,9 @@ describe('RoughCircle', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-circle-dashed', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, diff --git a/__tests__/ssr/rough-ellipse.spec.ts b/__tests__/ssr/rough-ellipse.spec.ts index 738c482..caa5632 100644 --- a/__tests__/ssr/rough-ellipse.spec.ts +++ b/__tests__/ssr/rough-ellipse.spec.ts @@ -45,6 +45,9 @@ describe('RoughEllipse', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-ellipse', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, diff --git a/__tests__/ssr/rough-path.spec.ts b/__tests__/ssr/rough-path.spec.ts index 028c726..c40234b 100644 --- a/__tests__/ssr/rough-path.spec.ts +++ b/__tests__/ssr/rough-path.spec.ts @@ -41,6 +41,9 @@ describe('RoughPath', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-path', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -62,6 +65,9 @@ describe('RoughPath', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-path-transform', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, diff --git a/__tests__/ssr/rough-polyline.spec.ts b/__tests__/ssr/rough-polyline.spec.ts index 57debda..93b4b91 100644 --- a/__tests__/ssr/rough-polyline.spec.ts +++ b/__tests__/ssr/rough-polyline.spec.ts @@ -47,6 +47,9 @@ describe('RoughPolyline', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-polyline', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, diff --git a/__tests__/ssr/rough-rect.spec.ts b/__tests__/ssr/rough-rect.spec.ts index 9711c33..8d45f56 100644 --- a/__tests__/ssr/rough-rect.spec.ts +++ b/__tests__/ssr/rough-rect.spec.ts @@ -44,6 +44,9 @@ describe('RoughRect', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-rect', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -67,6 +70,9 @@ describe('RoughRect', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-rect-stroke', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -94,6 +100,9 @@ describe('RoughRect', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-rect-dropshadow', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, @@ -120,6 +129,9 @@ describe('RoughRect', () => { expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot( dir, 'rough-rect-rerender', + { + maxError: 1000, + }, ); expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot( dir, diff --git a/packages/site/docs/index.md b/packages/site/docs/index.md index 5db5e73..37fe2fd 100644 --- a/packages/site/docs/index.md +++ b/packages/site/docs/index.md @@ -207,6 +207,22 @@ call(() => { } }); + // evenodd fill rule + const star = new Path({ + d: 'M150 0 L121 90 L198 35 L102 35 L179 90 Z', + fill: '#F67676', + fillRule: 'evenodd', + tessellationMethod: TesselationMethod.LIBTESS, // instead of earcut + }); + canvas.appendChild(star); + + // holes + const ring = new Path({ + d: 'M 50 10 A 40 40 0 1 0 50 90 A 40 40 0 1 0 50 10 Z M 50 30 A 20 20 0 1 1 50 70 A 20 20 0 1 1 50 30 Z', + fill: '#F67676', + }); + canvas.appendChild(ring); + // SDF const text = new Text({ x: 300, diff --git a/packages/site/docs/zh/index.md b/packages/site/docs/zh/index.md index d7a70ae..1e46a6a 100644 --- a/packages/site/docs/zh/index.md +++ b/packages/site/docs/zh/index.md @@ -207,6 +207,22 @@ call(() => { } }); + // evenodd fill rule + const star = new Path({ + d: 'M150 0 L121 90 L198 35 L102 35 L179 90 Z', + fill: '#F67676', + fillRule: 'evenodd', + tessellationMethod: TesselationMethod.LIBTESS, // instead of earcut + }); + canvas.appendChild(star); + + // holes + const ring = new Path({ + d: 'M 50 10 A 40 40 0 1 0 50 90 A 40 40 0 1 0 50 10 Z M 50 30 A 20 20 0 1 1 50 70 A 20 20 0 1 1 50 30 Z', + fill: '#F67676', + }); + canvas.appendChild(ring); + // SDF const text = new Text({ x: 300,