Commit Graph

76972 Commits

Author SHA1 Message Date
Matthias Clasen
2a740e31ef gtk-demo: Add a demo for path ops
This demo is called Glyphs, since that is what
it works with.
2023-07-05 22:46:48 -04:00
Matthias Clasen
b32a16880a Add API for pathops
The new APIs here are:
gsk_path_union
gsk_path_intersection
gsk_path_difference
gsk_path_symmetric_difference
gsk_path_simplify
2023-07-05 22:46:48 -04:00
Matthias Clasen
d0e63f83be Add some tests for pathops 2023-07-05 22:45:40 -04:00
Matthias Clasen
eba1676e31 Implement path ops
Implement boolean operations on paths.
2023-07-05 19:46:52 -04:00
Matthias Clasen
de17a904b4 Add a debug key for paths
Not used yet.
2023-07-05 19:46:52 -04:00
Matthias Clasen
0a264f3c1d Add a private getter for path flags
The flags contain some useful information
that will be used in the path ops implementation.
2023-07-05 19:46:52 -04:00
Matthias Clasen
5ba56b5ae4 Add a test for tangents of degenerate curves
The stroker relies on these to work.
2023-07-05 16:02:20 -04:00
Matthias Clasen
3a83f48034 curve: Handle degenerate cases
Nothing prevents control points from being identical,
and if that happens, some of our constructions involving
tangents and normals break down. Handle these cases in
get_{start,end}_tangent and offset, for the case of
cubics.
2023-07-05 16:02:20 -04:00
Matthias Clasen
a38d0ae91e Add a performance test for curve eval
All curve types are equally fast here.
2023-07-05 16:02:20 -04:00
Matthias Clasen
6f0816629d Add a performance test for curve intersection
This shows how much more expensive curve
intersections are.
2023-07-05 16:02:20 -04:00
Matthias Clasen
135dd6bfae Add curve split tests 2023-07-05 16:02:20 -04:00
Matthias Clasen
0f45503bf7 Add special-case curve tests 2023-07-05 16:02:20 -04:00
Matthias Clasen
ac8279dd8b Add curve match tests
Add tests that check that the curve api agrees on
values for a quadratic and its equivalent cubic
and conic curves.
2023-07-05 16:02:20 -04:00
Matthias Clasen
f4fffea88d Add curve intersection and bounds tests
These tests check that gsk_curve_intersect finds
the intersections we want and get_bounds returns
propert bounding boxes.
2023-07-05 16:02:20 -04:00
Matthias Clasen
ab0c720022 curve: Add gsk_curve_intersect
Add a way to find the intersections of two curves.
We can handle some curve-line intersections directly,
the general case is handled via bisecting.

This will be used in stroking and path ops.
2023-07-05 15:51:19 -04:00
Matthias Clasen
26d8d4c33d curve: Add gsk_curve_print
Useful for debugging.
2023-07-05 15:01:53 -04:00
Matthias Clasen
1a03efb181 curve: Add gsk_curve_get_curvature
This will be used in the stroker.
2023-07-05 15:01:53 -04:00
Matthias Clasen
df4696256c curve: Add gsk_curve_get_normal
Its easy but thats no reason not to have this api.
2023-07-05 15:01:53 -04:00
Matthias Clasen
45ba4e1bda curve: Add gsk_curve_get_bounds
Add getters for bounding boxes of curves.

Bounding boxes are needed to implement intersection
via bisecting.
2023-07-05 15:01:52 -04:00
Matthias Clasen
c258e275cc curve: Add some curve utilities
Internal apis:
- gsk_curve_get_curvature_points
- gsk_curve_get_cusps

These apis will be used in the stroker
and in path ops.
2023-07-05 15:01:19 -04:00
Matthias Clasen
280dff5350 Add a bounding box type
graphene_rect_t does not quite work for this purpose.
2023-07-05 15:01:19 -04:00
Matthias Clasen
31403b9299 tools: Add gtk4-path-tool
This comes in handy for testing, among other things.

For now, this supports decomposing, transforming,
reversing, restricting, rendering and preview.
2023-07-05 14:58:50 -04:00
Matthias Clasen
86b853f3fd Add decomposition tests
We don't have good error bounds for conics,
unfortunately. But we can test that we decompose
into the right curves.
2023-07-05 14:58:50 -04:00
Matthias Clasen
c9f5fa004e path: Allow limiting curve types in foreach
This is useful if your rendering system can't
handle certain kinds of curves, such as conics.
2023-07-05 14:58:50 -04:00
Matthias Clasen
4a9e4f5f9f curve: Add gsk_curve_decompose_curve
This is mainly useful for decomposing a conic into
cubics. The criterion here for terminating the
subdivision is very improvised.

But it also allows for other use cases, such as
raising the degree of quadratics to cubics.

An auxiliary API introduced here is gsk_curve_elevate.
2023-07-05 14:58:30 -04:00
Matthias Clasen
e03585e89f API: Add gsk_path_transform
This is an obvious operation to want for paths.
2023-07-05 13:43:57 -04:00
Matthias Clasen
f0bc4b5dfa API: Add gsk_path_reverse
This is a natural operation, and useful for debugging things.
2023-07-05 13:43:57 -04:00
Matthias Clasen
deb24472c0 Add a test for gsk_curve_reverse
The stroker relies on this working.
2023-07-05 13:43:57 -04:00
Matthias Clasen
110ca9b38e curve: Add gsk_curve_reverse
This is a useful operation that will be used,
among other places, in stroking.
2023-07-05 13:43:57 -04:00
Matthias Clasen
31119ce478 Update affected tests
We preserve quadratics in the SVG path roundtrip
tests now.
2023-07-05 13:42:45 -04:00
Matthias Clasen
10ee8f174b Add quadratic curves
API-wise, this adds
- GSK_PATH_QUAD
- GSK_PATH_FOREACH_ALLOW_QUAD
- gsk_path_builder_quad_to and _rel_quad_to
2023-07-05 13:42:45 -04:00
Matthias Clasen
6da54c61b4 Rename curve to cubic
This is to make room in the api for quadratic curves.

In detail:
 - Replace GSK_PATH_CURVE by _CUBIC
 - Rename gsk_path_builder_curve_to to _cubic_to
 - Replace GSK_PATH_FOREACH_ALLOW_CURVE with _CUBIC
 - Replace GskCurveCurve with GskCubicCurve
2023-07-05 13:42:45 -04:00
Matthias Clasen
b24d585b27 gsk_path_measure_is_closed -> gsk_path_is_closed
This is a property of the path that doesn't need
a measure to determine, so move the API to GskPath.
2023-07-05 13:35:42 -04:00
Matthias Clasen
cfbfc9cf61 contour: Handle reverse circle segments
If we can't append a circle contour, just
convert to a standard contour. This warning
was occasionally causing tests to fail
(when a suitable random path gets generated).
2023-07-02 10:39:15 -04:00
Matthias Clasen
2efbebec37 Clean up fill and stroke node apis
We were missing consts in a few places.
2023-07-02 09:03:39 -04:00
Matthias Clasen
bbdc30ffee gsk: Use stroke bounds for the stroke node
We have the right api to use.
2023-07-02 01:00:41 -04:00
Matthias Clasen
001aaf44d2 Private header cleanup
These includes break using the private headers
in internal tests, so fix them up to work for
that case.
2023-07-01 21:47:41 -04:00
Matthias Clasen
802d539b05 path_text demo: Fixup
We don't want any filtering by curve type here.
2023-07-01 18:58:42 -04:00
Matthias Clasen
001ac59a6b pathmeasure: Drop some unused apis
We are not convinced that it is a good idea
to expose the concept of contours, and these
apis are entirely unused, so drop them.
2023-07-01 16:04:29 -04:00
Matthias Clasen
1a85ba7451 curve: Explicitly initialize memory
Unitialized memory warnings aren't fun.
2023-06-30 07:48:31 -04:00
Matthias Clasen
750088f01c Be less demanding in the get_point test
When looking for discontinuities, there
is no need to check for epsilons. As we
move close to the end of one contour / the
beginning of the next, the path length distance
between the two points will get arbitrarily
small, so we can just check that the distance
between the points is more than twice that.

This makes spurious failures of the /path/get_point
test go away.
2023-06-30 07:47:58 -04:00
Matthias Clasen
db2a167ea2 Plug a memory leak in the path tests 2023-06-30 07:47:52 -04:00
Matthias Clasen
cdca291962 Only test conic weights between 1/20 and 20
The rest just give us no end of numeric trouble.
2023-06-30 07:47:44 -04:00
Matthias Clasen
ba5f7d77f8 pathbuilder: Avoid trouble with sincos
The Windows builds seem to have problem with
this handling of sincos(), so do it the same
way we do it elsewere, by defining _sincos().
2023-06-30 07:47:44 -04:00
Matthias Clasen
17726a4330 Make gsk_stroke_to_cairo public
It comes in handy, and does no harm.
2023-06-30 07:47:44 -04:00
Matthias Clasen
b47cbd74c0 Add comment for conic curves 2023-06-30 07:47:04 -04:00
Matthias Clasen
84e8f3db83 Docs: Fix a typo 2023-06-30 07:47:04 -04:00
Matthias Clasen
ae22094fb7 Documentation fixes
gi-docgen can't handle an indent > 2 in continuation lines.
2023-06-30 07:45:12 -04:00
Matthias Clasen
c3061916bc curve: Match skia more precisely
Close reading of sources revealed that we
were not actually using the same conditions
as skia here, causing our measurements to
come out slightly different.

With this change, we are in almost perfect
agreement with skia.
2023-06-30 07:44:21 -04:00
Matthias Clasen
87346d3151 curve: Cosmetic 2023-06-30 07:44:13 -04:00