From 4c0c7cd3545ef8be42c428459a7451b77c7d5540 Mon Sep 17 00:00:00 2001 From: puxiao Date: Sun, 29 Sep 2024 10:41:25 +0800 Subject: [PATCH] fix: resolve exceptions when width or height are 0 --- packages/core/src/graphics/path/path.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/core/src/graphics/path/path.ts b/packages/core/src/graphics/path/path.ts index ff07811..c4be2e8 100644 --- a/packages/core/src/graphics/path/path.ts +++ b/packages/core/src/graphics/path/path.ts @@ -89,6 +89,16 @@ export class SuikaPath extends SuikaGraphics { return this.geoPath!; } + private clampSize(partialAttrs: Partial) { + if (partialAttrs.width !== undefined) { + partialAttrs.width = Math.max(partialAttrs.width, 0.0001); + } + + if (partialAttrs.height !== undefined) { + partialAttrs.height = Math.max(partialAttrs.height, 0.0001); + } + } + /** * update attributes * TODO: optimize @@ -97,12 +107,14 @@ export class SuikaPath extends SuikaGraphics { partialAttrs: Partial, opts?: { finishRecomputed?: boolean }, ) { + partialAttrs = cloneDeep(partialAttrs); + this.clampSize(partialAttrs); + if (opts?.finishRecomputed) { super.updateAttrs(partialAttrs); return; } - partialAttrs = cloneDeep(partialAttrs); this.checkAndFixUpdatedAttrs(partialAttrs); const keys = Object.keys(partialAttrs); @@ -156,6 +168,7 @@ export class SuikaPath extends SuikaGraphics { flip: flipWhenResize, }); rect.transform = multiplyMatrix(invertMatrix(parentTf), rect.transform); + this.clampSize(rect); const newAttrs: Partial = rect; const newPathData = this.recomputedPathData(rect.width, rect.height); return { ...newAttrs, pathData: newPathData };