Skip to content

Visualize Your Ideas With Code

fix: restrict the corner radius of a rectangle (#9)

Jacobcc86a4a6d5b4
diff --git a/src/helpers/CanvasHelper.ts b/src/helpers/CanvasHelper.ts
index eb4c9b64..4fa51a89 100644
--- a/src/helpers/CanvasHelper.ts
+++ b/src/helpers/CanvasHelper.ts
@@ -25,8 +25,13 @@ export const CanvasHelper = {
height: number,
radius: PossibleSpacing,
): T {
- //FIXME Handle too small radii
const spacing = new Spacing(radius);
+ const maxRadius = Math.min(height / 2, width / 2);
+ spacing.left = Math.min(spacing.left, maxRadius);
+ spacing.right = Math.min(spacing.right, maxRadius);
+ spacing.top = Math.min(spacing.top, maxRadius);
+ spacing.bottom = Math.min(spacing.bottom, maxRadius);
+
ctx.moveTo(x + spacing.left, y);
ctx.arcTo(x + width, y, x + width, y + height, spacing.top);
ctx.arcTo(x + width, y + height, x, y + height, spacing.right);