diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index c721e11..f0ed1f7 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -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) diff --git a/tests/benchmark_paths.nim b/tests/benchmark_paths.nim index 82d2ece..98e9072 100644 --- a/tests/benchmark_paths.nim +++ b/tests/benchmark_paths.nim @@ -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))