mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 20:28:02 +02:00
path: Simplify close_path
Instead of explicitly computing the flag in close_path, manually close the path with a line_to, then drop the last operation if it is a line_to (it might be another operation if the line_to was ignored because it would have been degenerate).
This commit is contained in:
parent
641d314b9a
commit
f3e7677109
1 changed files with 17 additions and 20 deletions
|
|
@ -655,27 +655,24 @@ _cairo_path_fixed_close_path (cairo_path_fixed_t *path)
|
|||
if (! path->has_current_point)
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
||||
/* If the previous op was also a LINE_TO back to the start, discard it */
|
||||
if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO) {
|
||||
if (path->current_point.x == path->last_move_point.x &&
|
||||
path->current_point.y == path->last_move_point.y)
|
||||
{
|
||||
cairo_path_buf_t *buf;
|
||||
cairo_point_t *p;
|
||||
/*
|
||||
* Add a line_to, to compute flags and solve any degeneracy.
|
||||
* It will be removed later (if it was actually added).
|
||||
*/
|
||||
status = _cairo_path_fixed_line_to (path,
|
||||
path->last_move_point.x,
|
||||
path->last_move_point.y);
|
||||
if (unlikely (status))
|
||||
return status;
|
||||
|
||||
buf = cairo_path_tail (path);
|
||||
if (likely (buf->num_points >= 2)) {
|
||||
p = &buf->points[buf->num_points-2];
|
||||
} else {
|
||||
cairo_path_buf_t *prev_buf = cairo_path_buf_prev (buf);
|
||||
p = &prev_buf->points[prev_buf->num_points - (2 - buf->num_points)];
|
||||
}
|
||||
|
||||
path->current_point = *p;
|
||||
buf->num_ops--;
|
||||
buf->num_points--;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If the command used to close the path is a line_to, drop it.
|
||||
* We must check that last command is actually a line_to,
|
||||
* because the path could have been closed with a curve_to (and
|
||||
* the previous line_to not added as it would be degenerate).
|
||||
*/
|
||||
if (_cairo_path_fixed_last_op (path) == CAIRO_PATH_OP_LINE_TO)
|
||||
_cairo_path_fixed_drop_line_to (path);
|
||||
|
||||
status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CLOSE_PATH, NULL, 0);
|
||||
if (unlikely (status))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue