This commit is contained in:
Ryan Oldenburg 2021-06-04 17:55:07 -05:00
parent 046556fdef
commit 9ccbcf7347
2 changed files with 15 additions and 8 deletions

View file

@ -25,7 +25,7 @@ type
RMove, RLine, RHLine, RVLine, RCubic, RSCubic, RQuad, RTQuad, RArc
PathCommand* = object
## Binary version of an SVG command
## Binary version of an SVG command.
kind*: PathCommandKind
numbers*: seq[float32]
@ -501,6 +501,18 @@ proc roundedRect*(
## Clockwise param can be used to subtract a rect from a path when using
## even-odd winding rule.
var
nw = nw
ne = ne
se = se
sw = sw
maxRadius = min(w / 2, h / 2)
nw = max(0, min(nw, maxRadius))
ne = max(0, min(ne, maxRadius))
se = max(0, min(se, maxRadius))
sw = max(0, min(sw, maxRadius))
if nw == 0 and ne == 0 and se == 0 and sw == 0:
path.rect(x, y, w, h, clockwise)
return
@ -508,12 +520,6 @@ proc roundedRect*(
let
s = splineCircleK
maxRadius = min(w / 2, h / 2)
nw = min(nw, maxRadius)
ne = min(ne, maxRadius)
se = min(se, maxRadius)
sw = min(sw, maxRadius)
t1 = vec2(x + nw, y)
t2 = vec2(x + w - ne, y)
r1 = vec2(x + w, y + ne)

View file

@ -12,6 +12,7 @@ timeIt "roundedRect":
const radius = 20
var path: Path
path.roundedRect(0, 0, 500, 300, radius, radius, radius, radius)
path.roundedRect(0.5, 0.5, 499, 299, radius, radius, radius, radius)
# path.roundedRect(0, 0, 500, 300, radius, radius, radius, radius)
image.fillPath(path, rgba(0, 0, 0, 255))