Commit Graph

76955 Commits

Author SHA1 Message Date
Matthias Clasen
73a06b6b2a curve: Add gsk_curve_get_normal
Its easy but thats no reason not to have this api.
2023-07-06 13:02:19 -04:00
Matthias Clasen
8258550df9 curve: Add gsk_curve_get_bounds
Add getters for bounding boxes of curves.

Bounding boxes are needed to implement intersection
via bisecting.
2023-07-06 13:02:19 -04:00
Matthias Clasen
6305725523 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-06 13:02:19 -04:00
Matthias Clasen
78f70a5720 Add a bounding box type
graphene_rect_t does not quite work for this purpose.
2023-07-06 13:02:19 -04:00
Matthias Clasen
02402b2881 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-06 13:00:21 -04:00
Matthias Clasen
71d03be38c 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-06 13:00:21 -04:00
Matthias Clasen
be6238096b 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-06 13:00:21 -04:00
Matthias Clasen
27a2e97852 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-06 13:00:21 -04:00
Matthias Clasen
f848f44613 API: Add gsk_path_transform
This is an obvious operation to want for paths.
2023-07-06 13:00:20 -04:00
Matthias Clasen
59585d2de4 API: Add gsk_path_reverse
This is a natural operation, and useful for debugging things.
2023-07-06 13:00:20 -04:00
Matthias Clasen
09b5564fa8 Add a test for gsk_curve_reverse
The stroker relies on this working.
2023-07-06 13:00:20 -04:00
Matthias Clasen
54828e0a74 curve: Add gsk_curve_reverse
This is a useful operation that will be used,
among other places, in stroking.
2023-07-06 13:00:20 -04:00
Matthias Clasen
60e78cb210 Update affected tests
We preserve quadratics in the SVG path roundtrip
tests now.
2023-07-06 12:56:47 -04:00
Matthias Clasen
ee0414f243 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-06 12:56:47 -04:00
Matthias Clasen
f813bd808b 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-06 12:56:45 -04:00
Matthias Clasen
40d0c1d73f 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-06 12:55:09 -04:00
Matthias Clasen
b4cd601baa 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-06 12:54:47 -04:00
Matthias Clasen
6428b6654d Clean up fill and stroke node apis
We were missing consts in a few places.
2023-07-06 12:54:47 -04:00
Matthias Clasen
06503f9604 gsk: Use stroke bounds for the stroke node
We have the right api to use.
2023-07-06 12:54:47 -04:00
Matthias Clasen
4b0313c1cd Private header cleanup
These includes break using the private headers
in internal tests, so fix them up to work for
that case.
2023-07-06 12:54:47 -04:00
Matthias Clasen
32a934ecaa path_text demo: Fixup
We don't want any filtering by curve type here.
2023-07-06 12:54:47 -04:00
Matthias Clasen
69d1826a6d pathmeasure: Drop first/last
We no longer restrict measures, so n_contours
is sufficient.
2023-07-06 12:54:10 -04:00
Matthias Clasen
1fac0f5391 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-06 12:50:30 -04:00
Matthias Clasen
ae085c3ae9 curve: Explicitly initialize memory
Unitialized memory warnings aren't fun.
2023-07-06 12:50:30 -04:00
Matthias Clasen
47c471cffa 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-07-06 12:50:30 -04:00
Matthias Clasen
08d6e24370 Plug a memory leak in the path tests 2023-07-06 12:50:30 -04:00
Matthias Clasen
3d65c0da84 Only test conic weights between 1/20 and 20
The rest just give us no end of numeric trouble.
2023-07-06 12:50:30 -04:00
Matthias Clasen
d5ab5336aa 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-07-06 12:50:30 -04:00
Matthias Clasen
726ebecc82 Make gsk_stroke_to_cairo public
It comes in handy, and does no harm.
2023-07-06 12:50:30 -04:00
Matthias Clasen
e6ba20951b Add comment for conic curves 2023-07-06 12:50:30 -04:00
Matthias Clasen
8876b44369 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-07-06 12:50:30 -04:00
Matthias Clasen
7cbd15a70f curve: Cosmetic 2023-07-06 12:50:30 -04:00
Matthias Clasen
f1624351ba tests: Less degenerate, please
We were inadvertendly using 95% degenerate paths,
instead of 5%. Oops.
2023-07-06 12:50:30 -04:00
Matthias Clasen
24edad6eb9 contour: Reimplement get_winding
Follow the usual implementation more closely,
and drop reporting a separate 'on_edge' bit.

This was wrong in some cases, and we don't
need it. See the testcase in this commit
for a case where 'on_edge' was wrongly
deciding that a point is inside.
2023-07-06 12:50:30 -04:00
Matthias Clasen
d82522da89 Add a test for a bad case
This is narrowing down what goes wrong in the
segment test: We have an unevenly parameterized
cubic. This case gave me a lot of trouble.
2023-07-06 12:50:30 -04:00
Matthias Clasen
ccc41d67a4 tests: Handle internal tests better
We have a better way of testing private API now,
by linking statically.
2023-07-06 12:50:30 -04:00
Matthias Clasen
02d13963a7 Fix a stack overflow in a test
The test_in_fill_rotated test was mistakenly
assuming that conics come with 4 points, when
the only have 3. Oops.
2023-07-06 12:50:30 -04:00
Matthias Clasen
b052b5d5c7 Fix memory overruns in the path parser
It turns out that using strchr() to identify
chars in your string isn't safe since strchr
happily matches the '\0' at the end of the input.

If we are not careful, that makes use walk
off the end of the string.

This issue was found by asan.
2023-07-06 12:50:30 -04:00
Matthias Clasen
15cd57727e Fix curve tests in release builds
g_test_init sabotages tests in release builds,
we have to use (g_test_init) to avoid the sabotage.

At the same time, we have to avoid using g_assert,
since that's a no-op in release builds.
2023-07-06 12:50:30 -04:00
Matthias Clasen
3d8bf36945 Fix fp16 with asan
The IFUNC resolvers that we are using here get
run early, before asan had a chance to set up its
plumbing, and therefore things go badly if they
are compiled with asan. Turning it off makes things
work again.

The gcc bug tracking this problem:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110442
2023-07-06 12:50:30 -04:00
Matthias Clasen
bd9a93d549 Docs cleanup
Rewrite the path docs for gi-docgen syntax.
2023-07-06 12:50:30 -04:00
Benjamin Otte
826efc4dff testsuite: Increase tolerances to make the path test work
I dislike the corner cases being so low (lower than 1% and off by a
whole point).
2023-06-19 18:18:44 +02:00
Benjamin Otte
d4705216ed path: Handle segments of degenerate curves via lines
When curves have long straight parts that decompose into a single line,
don't try to split them. Instead, split at a well-known position and a
the part of that long straight line as a line.

This gives way more accurate numbers and is more accurate than 1% for
everything but contours with very small weight and
start_point == end_point, where the error is closer to 1.5%.
2023-06-19 18:18:44 +02:00
Benjamin Otte
caf1b0b86c curve: Add a reason to decomposition
When decomposing curves that are too straight, we may emit lines for
long parts of the curve. These lines do not properly map
  t => distance
and it is better to treat them as a regular line than a curve.

This reason argument gives that information.

No users so far, that will happen in followup commits.
2023-06-19 18:18:44 +02:00
Benjamin Otte
5f634ee30f path: Move gsk_path_new_from_cairo() away
This is a regular path creation API, so treat it that way.

On top, it is rather awkward if the only constructor for a path that is
immediately visible to people reading the docs is the one that takes a
Cairo path - when we want to deprecate Cairo.
2023-06-19 18:18:44 +02:00
Matthias Clasen
1054485afb gtk-demo: Rewrite the text mask demo
Use GtkSnapshot and GskPath instead of cairo for this.
2023-06-19 18:18:44 +02:00
Benjamin Otte
4bb65eaf4c gtk-demo: Make path-text demo use gsk_builder_add_layout() 2023-06-19 18:18:44 +02:00
Matthias Clasen
043f5db9de path fill demo: Use gsk_path_builder_add_layout
We have an api now to hide the cairo use.
2023-06-19 18:18:44 +02:00
Matthias Clasen
5c3a5761b4 gsk: Add gsk_path_builder_add_layout
This api makes it easy to turn text into a path that
can be further manipulated. The implementation currently
goes via cairo.
2023-06-19 18:18:44 +02:00
Benjamin Otte
9ef17b9b32 path: Add gsk_path_builder_add_ellipse() 2023-06-19 18:18:44 +02:00