Skip to content

Commit

Permalink
Fix: deal with radius < 0
Browse files Browse the repository at this point in the history
  • Loading branch information
djowel committed May 22, 2024
1 parent c81e68c commit f8aa6b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
6 changes: 1 addition & 5 deletions lib/impl/skia/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,7 @@ namespace cycfi::artist
bool ccw
)
{
if (radius <= 0)
{
line_to(p);
return;
}
radius = std::max(radius, 0.0f);
auto start = start_angle * 180 / pi;
auto sweep = (end_angle - start_angle) * 180 / pi;
if (sweep < 0)
Expand Down
6 changes: 1 addition & 5 deletions lib/impl/skia/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ namespace cycfi::artist
float start_angle, float end_angle,
bool ccw)
{
if (radius <= 0)
{
line_to(p);
return;
}
radius = std::max(radius, 0.0f);
auto start = start_angle * 180 / pi;
auto sweep = (end_angle - start_angle) * 180 / pi;
if (sweep < 0)
Expand Down
Binary file modified test/macos_golden/quartz2d/shapes2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/macos_golden/skia/shapes2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 16 additions & 5 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,36 @@ void draw_round_rect(canvas& cnv, rect bounds, detail::corner_radii radius)
void basics2(canvas& cnv)
{
auto state = cnv.new_state();
rect bounds = {20, 20, 220, 120};

{
draw_round_rect(cnv, {50, 50, 250, 150}, {-1, 40, 40, -1}); // Negative radius
draw_round_rect(cnv, bounds, {-1, 40, 40, -1}); // Negative radius

cnv.fill_style(colors::light_sea_green.opacity(0.8));
cnv.fill_preserve();

cnv.stroke_style(colors::goldenrod.opacity(0.8));
cnv.line_width(3);
cnv.stroke_style(colors::antique_white.opacity(0.8));
cnv.line_width(2);
cnv.stroke();
}
{
draw_round_rect(cnv, {20, 20, 220, 120}, {15, 40, 40, 15});
draw_round_rect(cnv, bounds.move(20, 20), {15, 40, 40, 15});

cnv.fill_style(colors::navy_blue.opacity(0.5));
cnv.fill_preserve();

cnv.stroke_style(colors::antique_white.opacity(0.5));
cnv.line_width(3);
cnv.line_width(2);
cnv.stroke();
}
{
draw_round_rect(cnv, bounds.move(40, 40), {0, 0, 0, 0});

cnv.fill_style(colors::indian_red.opacity(0.5));
cnv.fill_preserve();

cnv.stroke_style(colors::antique_white.opacity(0.5));
cnv.line_width(2);
cnv.stroke();
}
}
Expand Down

0 comments on commit f8aa6b2

Please sign in to comment.