mirror of
https://github.com/motion-canvas/motion-canvas.git
synced 2026-01-12 15:28:03 -05:00
fix: restrict the corner radius of a rectangle (#9)
The maximum radius can't be bigger than half the size of the rectangle. Fixes #8
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user