Add API for boolean operations on paths

The new APIs here are:
gsk_path_union
gsk_path_intersection
gsk_path_difference
gsk_path_symmetric_difference
gsk_path_simplify
This commit is contained in:
Matthias Clasen
2023-07-01 21:33:02 -04:00
parent 42eaacbab4
commit 3b2ab7ad1e
2 changed files with 130 additions and 0 deletions

View File

@@ -193,6 +193,30 @@ gboolean gsk_path_foreach_intersection (GskPath
GskPathIntersectionFunc func,
gpointer user_data);
GDK_AVAILABLE_IN_4_14
GskPath * gsk_path_union (GskPath *first,
GskPath *second,
GskFillRule fill_rule);
GDK_AVAILABLE_IN_4_14
GskPath * gsk_path_intersection (GskPath *first,
GskPath *second,
GskFillRule fill_rule);
GDK_AVAILABLE_IN_4_14
GskPath * gsk_path_difference (GskPath *first,
GskPath *second,
GskFillRule fill_rule);
GDK_AVAILABLE_IN_4_14
GskPath * gsk_path_symmetric_difference (GskPath *first,
GskPath *second,
GskFillRule fill_rule);
GDK_AVAILABLE_IN_4_14
GskPath * gsk_path_simplify (GskPath *self,
GskFillRule fill_rule);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskPath, gsk_path_unref)
G_END_DECLS

View File

@@ -1708,5 +1708,111 @@ gsk_path_op (GskPathOp operation,
}
/* }}} */
/* {{{ Pathops API */
/**
* gsk_path_simplify:
* @self: a `GskPath`
* @fill_rule: a `GskFillRule`
*
* Create a new path that describes the same area as @self,
* without overlapping contours.
*
* Returns: a new `GskPath`
*
* Since: 4.14
*/
GskPath *
gsk_path_simplify (GskPath *self,
GskFillRule fill_rule)
{
return gsk_path_op (GSK_PATH_OP_SIMPLIFY, fill_rule, self, NULL);
}
/**
* gsk_path_union:
* @first: a `GskPath`
* @second: a `GskPath`
* @fill_rule: a `GskFillRule`
*
* Create a new path that describes the union of the areas
* of the given paths.
*
* Returns: a new `GskPath`
*
* Since: 4.14
*/
GskPath *
gsk_path_union (GskPath *first,
GskPath *second,
GskFillRule fill_rule)
{
return gsk_path_op (GSK_PATH_OP_UNION, fill_rule, first, second);
}
/**
* gsk_path_intersection:
* @first: a `GskPath`
* @second: a `GskPath`
* @fill_rule: a `GskFillRule`
*
* Create a new path that describes the intersection of the areas
* of the given paths.
*
* Returns: a new `GskPath`
*
* Since: 4.14
*/
GskPath *
gsk_path_intersection (GskPath *first,
GskPath *second,
GskFillRule fill_rule)
{
return gsk_path_op (GSK_PATH_OP_INTERSECTION, fill_rule, first, second);
}
/**
* gsk_path_difference:
* @first: a `GskPath`
* @second: a `GskPath`
* @fill_rule: a `GskFillRule`
*
* Create a new path that describes the difference of the areas
* of the given paths.
*
* Returns: a new `GskPath`
*
* Since: 4.14
*/
GskPath *
gsk_path_difference (GskPath *first,
GskPath *second,
GskFillRule fill_rule)
{
return gsk_path_op (GSK_PATH_OP_DIFFERENCE, fill_rule, first, second);
}
/**
* gsk_path_symmetric_difference:
* @first: a `GskPath`
* @second: a `GskPath`
* @fill_rule: a `GskFillRule`
*
* Create a new path that describes the symmetric difference
* of the areas of the given paths.
*
* Returns: a new `GskPath`
*
* Since: 4.14
*/
GskPath *
gsk_path_symmetric_difference (GskPath *first,
GskPath *second,
GskFillRule fill_rule)
{
return gsk_path_op (GSK_PATH_OP_XOR, fill_rule, first, second);
}
/* }}}} */
/* vim:set foldmethod=marker expandtab: */