Skip to content

Commit

Permalink
Refactor plutovg-path.c
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Aug 14, 2024
1 parent c7794dc commit 6e627af
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions source/plutovg-path.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ void plutovg_path_quad_to(plutovg_path_t* path, float x1, float y1, float x2, fl
{
float current_x, current_y;
plutovg_path_get_current_point(path, &current_x, &current_y);
if(path->elements.size == 0)
plutovg_path_move_to(path, 0, 0);
float cx = 2.f / 3.f * x1 + 1.f / 3.f * current_x;
float cy = 2.f / 3.f * y1 + 1.f / 3.f * current_y;
float cx1 = 2.f / 3.f * x1 + 1.f / 3.f * x2;
Expand All @@ -145,8 +143,6 @@ void plutovg_path_arc_to(plutovg_path_t* path, float rx, float ry, float angle,
{
float current_x, current_y;
plutovg_path_get_current_point(path, &current_x, &current_y);
if(path->elements.size == 0)
plutovg_path_move_to(path, 0, 0);
if(rx == 0.f || ry == 0.f || (current_x == x && current_y == y)) {
plutovg_path_line_to(path, x, y);
return;
Expand Down Expand Up @@ -215,19 +211,19 @@ void plutovg_path_arc_to(plutovg_path_t* path, float rx, float ry, float angle,
float x3 = cosf(th_end) + cx1;
float y3 = sinf(th_end) + cy1;

float x2 = x3 + t * sinf(th_end);
float y2 = y3 - t * cosf(th_end);
float cp2x = x3 + t * sinf(th_end);
float cp2y = y3 - t * cosf(th_end);

float x1 = cosf(th_start) - t * sinf(th_start);
float y1 = sinf(th_start) + t * cosf(th_start);
float cp1x = cosf(th_start) - t * sinf(th_start);
float cp1y = sinf(th_start) + t * cosf(th_start);

x1 += cx1;
y1 += cy1;
cp1x += cx1;
cp1y += cy1;

plutovg_matrix_map(&matrix, x1, y1, &x1, &y1);
plutovg_matrix_map(&matrix, x2, y2, &x2, &y2);
plutovg_matrix_map(&matrix, cp1x, cp1y, &cp1x, &cp1y);
plutovg_matrix_map(&matrix, cp2x, cp2y, &cp2x, &cp2y);
plutovg_matrix_map(&matrix, x3, y3, &x3, &y3);
plutovg_path_cubic_to(path, x1, y1, x2, y2, x3, y3);
plutovg_path_cubic_to(path, cp1x, cp1y, cp2x, cp2y, x3, y3);
}
}

Expand Down

0 comments on commit 6e627af

Please sign in to comment.