From e75ca180fff531b8224ef88b9e08c41ab6a7894f Mon Sep 17 00:00:00 2001 From: Kean Mariotti Date: Thu, 5 Jan 2023 16:50:38 +0000 Subject: [PATCH] Fix rects view (weird triangular shapes) Rectangles with property cornerRadius === 0 could result in weird triangular shapes being drawn instead of rectangles Fix: b/264541479 Test: follow steps in b/264541479 and check issue is gone Change-Id: I2421e47cdbf7c932218640f2553647ded676a80d --- tools/winscope/src/viewers/components/rects/canvas.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/winscope/src/viewers/components/rects/canvas.ts b/tools/winscope/src/viewers/components/rects/canvas.ts index cdc788c76..078c9ee43 100644 --- a/tools/winscope/src/viewers/components/rects/canvas.ts +++ b/tools/winscope/src/viewers/components/rects/canvas.ts @@ -253,7 +253,12 @@ export class Canvas { const height = rect.bottomRight.y - rect.topLeft.y; const width = rect.bottomRight.x - rect.topLeft.x; const minEdge = Math.min(height, width); - const cornerRadius = Math.min(rect.cornerRadius, minEdge / 2); + let cornerRadius = Math.min(rect.cornerRadius, minEdge / 2); + + // Force radius > 0, because radius === 0 could result in weird triangular shapes + // being drawn instead of rectangles. Seems like quadraticCurveTo() doesn't + // always handle properly the case with radius === 0. + cornerRadius = Math.max(cornerRadius, 0.01); // Create (rounded) rect shape return new THREE.Shape()