Bug 101763 - Bezier curve with matching start/end and control points is not rendered correctly
Summary: Bezier curve with matching start/end and control points is not rendered corre...
Status: RESOLVED MOVED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Chris Wilson
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-12 10:07 UTC by igagis@gmail.com
Modified: 2018-08-25 13:47 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
cairo_rel_curve_to(cr, 100, 100, 100, 100, 0, 0) (651 bytes, image/png)
2017-07-12 10:07 UTC, igagis@gmail.com
Details
cairo_rel_curve_to(cr, 100, 100, 101, 100, 0, 0) (392 bytes, image/png)
2017-07-12 10:07 UTC, igagis@gmail.com
Details
Reproducer (453 bytes, text/x-csrc)
2017-07-13 17:59 UTC, Uli Schlachter
Details
This patch makes the reproducer work correctly. No idea what other side-effects it might have. (449 bytes, patch)
2017-07-15 07:37 UTC, Uli Schlachter
Details | Splinter Review

Description igagis@gmail.com 2017-07-12 10:07:02 UTC
Created attachment 132628 [details]
cairo_rel_curve_to(cr, 100, 100, 100, 100, 0, 0)

Trying to render the bezier curve which has the end point same as start point and both control points are also matching, for example:

    cairo_move_to(cr, 100, 100);
    cairo_rel_curve_to(cr, 100, 100, 100, 100, 0, 0);

Results in wrong image.

Expected result:
For the example above, I would expect a 45 degrees diagonal line is drawn.

Actual result:
A dot at the current point location is drawn.

Note, that if make control points slightly differ the line is drawn.

See attachments for:
1) cairo_rel_curve_to(cr, 100, 100, 100, 100, 0, 0);
2) cairo_rel_curve_to(cr, 100, 100, 101, 100, 0, 0);
Comment 1 igagis@gmail.com 2017-07-12 10:07:33 UTC
Created attachment 132630 [details]
cairo_rel_curve_to(cr, 100, 100, 101, 100, 0, 0)
Comment 2 Uli Schlachter 2017-07-13 17:59:21 UTC
Created attachment 132671 [details]
Reproducer

I can reproduce with the attached program and, as already said, adding an offset of 1 makes "things work".

Are such degenerate curves even well-defined (the two control points coincide and so do the two end points)?
Comment 3 igagis@gmail.com 2017-07-13 18:06:59 UTC
I can say that in some other vector graphics implementations this case works as I described in expected result.
I can define the SVG image which essentially draws such Bezier curve and Firefox displays such SVG correctly, i.e. diagonal line is drawn. So, I assume cairo is not behaving naturally in this case.
Comment 4 Uli Schlachter 2017-07-15 07:37:18 UTC
What happens is:
_cairo_path_fixed_stroke_to_polygon is called and in its curve_to() callback it calls _cairo_spline_decompose() on this curve.
The original curve is (100,100)->(200,200)->(200,200)->(100,100) (these are its four control points) and it is decomposed into the following two curves:
(100,100)->(150,150)->(175,175)->(175,175)
(175,175)->(175,175)->(150,150)->(100,100)

The error now is 0 so points are added. The add_point callback of the spline is spline_to() and it gets the following arguments:
spline to (175,175) with tangent (0,0)
spline to (100,100) with tangent (-100,-100)

The problem is the tangent (0,0), which means that spline_to() just calls add_fan(). At this point I am lost on what is going on. This code ignores the point argument and only uses the passed-in point. Thus, only "things around (100,100)" happen.

With the following patch, things work as expected. Since I have no clue about the algorithm, I'm not sure how incorrect this is. I guess that the thought here was "tangent (0,0) can only happen if the points are all the same", which this example shows is wrong. However, since this is just a guess, I'll hope that someone with more of a clue looks at this. Oh and: The test suite should be checked for regressions.

Chris?
Andrea?
Anyone with some clue about this?
Comment 5 Uli Schlachter 2017-07-15 07:37:56 UTC
Created attachment 132696 [details] [review]
This patch makes the reproducer work correctly. No idea what other side-effects it might have.
Comment 6 GitLab Migration User 2018-08-25 13:47:00 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/191.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.