Skip to content

fix: negative cornerRadius of RegularPolygon no longer throws - #2078

Merged
lavrton merged 1 commit into
konvajs:masterfrom
Enesuygurs:fix/regular-polygon-negative-corner-radius
Oct 22, 2026
Merged

lavrton merged 1 commit into
konvajs:masterfrom
Enesuygurs:fix/regular-polygon-negative-corner-radius

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

A RegularPolygon with a negative cornerRadius (a number or an entry of the per-corner array) throws while drawing:

const poly = new Konva.RegularPolygon({
  x: 100,
  y: 100,
  sides: 5,
  radius: 50,
  fill: 'green',
  cornerRadius: -10,
});
layer.add(poly);
layer.draw(); // IndexSizeError in browsers, "RangeError: Radius value must be positive" with skia-canvas

The error is thrown inside the layer draw, so any shapes after the polygon aren't drawn either, and the hit graph throws in the same way. Since the negative radius fix in 806dbec, Rect and Tag draw a negative cornerRadius as no rounding. RegularPolygon, however, goes through Util.drawRoundedPolygonPath(), which passes the negative value on to context.arcTo().

drawRoundedPolygonPath() now clamps each corner radius to 0 before scaling it, so a negative corner draws sharp, the same as 0.

The new test in RegularPolygon-test.ts draws polygons with cornerRadius: -10 and [-5, 10, -5, 10, -5] and compares them with 0 and [0, 10, 0, 10, 0]. Without the change it fails with RangeError: Radius value must be positive on skia, and the drawing differs on node-canvas. These all pass:

  • npm run test:node:canvas (1285 passing)
  • npm run test:node:skia (1288 passing)
  • npm run test:types
  • tsc --noEmit
  • prettier

A negative corner radius reached context.arcTo(), which throws for a
negative radius, aborting the layer draw. Clamp each corner radius to 0,
as rounded rects and Tag already do.
@lavrton
lavrton merged commit b53f145 into konvajs:master Oct 22, 2026
@lavrton

lavrton commented Oct 22, 2026

Copy link
Copy Markdown
Member

THanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants