Bug 359805 - strange loss of drawing precision when drawing circles
Summary: strange loss of drawing precision when drawing circles
Status: CONFIRMED
Alias: None
Product: kig
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: David E. Narvaez
URL: http://dmf.unicatt.it/~paolini/kig/bugs/
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-25 19:44 UTC by Maurizio Paolini
Modified: 2016-04-01 22:35 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
two tangent circles (6.03 KB, application/xml)
2016-03-01 05:16 UTC, Maurizio Paolini
Details
patch proposal (4.49 KB, patch)
2016-03-05 21:15 UTC, Maurizio Paolini
Details
patch file (clean version) (2.72 KB, patch)
2016-03-06 16:46 UTC, Maurizio Paolini
Details
png showing a (different) problem when drawing circles/arcs (10.53 KB, image/png)
2016-03-23 19:10 UTC, Maurizio Paolini
Details
same as previous, but with unmodified kig (10.04 KB, image/png)
2016-03-23 19:12 UTC, Maurizio Paolini
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maurizio Paolini 2016-02-25 19:44:47 UTC
In many cases the graphic drawing presents strange precision loss, like circles that should go through the same point but they don't.  Numerical error does not explain the result.
In the web page above there is an example. An arc and a circle are constructed such that
the circle is the support circle of the arc.  They should be exactly superposed, but they aren't
(zoom in an area of size approximately 1)
Please note that:
- if exported in png format the precision error is present
- if exported in SVG (or other vector formats) the result is instead CORRECT!
This suggests that the problem is not in the kig "calc" engine, but somewhere else.

In my opinion this problems was not present in earlier kig versions (say kde2 or kde3),
but it is there since quite some time.

It is quite annoying...

Reproducible: Always

Steps to Reproduce:
1. Download "bug.kig" from the web page
2. Zoom around an end-point of the arc (near the origin) such that the window size
is of order one

Actual Results:  
The arc (thick line) is separated from the circle (thin line)

Expected Results:  
The arc should be perfectly superposed with the circle

Numerical precision cannot be blamed, this example is not that extreme!
Comment 1 Maurizio Paolini 2016-02-25 19:52:30 UTC
One comment that could help debugging:
Once we have the zoomed window after steps 1 and 2 above:

- move the cursor over a point of the displayed thin line (beyond the end-point
of the arc): nothing appears
- move the cursor over a point where the thin line *should* be (on the prolongation of the
thick line), and surprisingly you see the text "select this circle", meaning that internally the
circle positioning is correct
Comment 2 Maurizio Paolini 2016-03-01 05:16:48 UTC
Created attachment 97618 [details]
two tangent circles

This is a striking example.  The two circles are constructed as tangent, however their representation in the kig windows is not!
Further digging leads me to suspect that the problem is not in kig, but in
the QT method

QPainter::drawEllipse

I can motivate, if necessary
Comment 3 Maurizio Paolini 2016-03-01 05:40:38 UTC
Maybe this issue is related to this qt bugreport:
https://bugreports.qt.io/browse/QTBUG-1292
Comment 4 Maurizio Paolini 2016-03-05 14:32:54 UTC
A simple workaround to the problem consists in commenting the
method "CircleImp::draw" in both objects/circle_imp.cc and
objects/circle_imp.h.

In this way kig falls back to the generic method for drawing conics, which works fine
for circles.  With this workaround the last attachments with two tangent circles gives
the expected behaviour
Comment 5 Maurizio Paolini 2016-03-05 21:15:06 UTC
Created attachment 97700 [details]
patch proposal

This patch adds toScreenF methods alongside toScreen and uses it to create a QRectF instead of a QRect in CircleImp::draw
Comment 6 Maurizio Paolini 2016-03-06 16:46:13 UTC
Created attachment 97715 [details]
patch file (clean version)

the previous patch file contained unrelated differences
Comment 7 Rex Dieter 2016-03-10 13:57:32 UTC
I'd recommend submitting your patch to reviewboard.kde.org, that's the ideal way.
Comment 8 Maurizio Paolini 2016-03-17 18:19:29 UTC
(In reply to Rex Dieter from comment #7)
> I'd recommend submitting your patch to reviewboard.kde.org, that's the ideal
> way.

Done... but no comments so far.  Now I am not sure what to do.  Should I push my commit?
Should I wait some more (how long)?
Comment 9 Maurizio Paolini 2016-03-22 22:43:37 UTC
solved via reviewboard:
https://git.reviewboard.kde.org/r/127354/
Comment 10 Maurizio Paolini 2016-03-23 18:59:40 UTC
An identical problem is present when drawing circular arcs!  Since the correction is minimal and perfectly similar to what was done for circular arcs I took the liberty of pushing it into
origin/master.
The commit is visible as:
http://commits.kde.org/kig/2f22efe4cb70960cf2362680783477ed44b2492e
Comment 11 Maurizio Paolini 2016-03-23 19:07:36 UTC
Anyway, there are still problems when drawing arcs and circles; apparently of a different
nature: it becomes apparent when the radius of circle/arc is much larger then the size
for the displayed canvas.  I will attach an image that shows the problem.
It shows a zoom (window from (1.8;1.8) to (2.2;2.2) ) of a construction of an arc by three
points (one endpoint is inside the window) and the circle that supports that arc: it should
be perfectly superposed.  However the figure was obtained by forcing kig to draw the arc
using the generic method for curves.
As can be seen, the generic method for curves works far better then with the direct use of
Qt primitives.  kig with its standard drawArc would produce a drawing more or less superposed
with the circle.  At the moment I don't know if this is a Qt problem or a kig problem
Comment 12 Maurizio Paolini 2016-03-23 19:10:20 UTC
Created attachment 98046 [details]
png showing a (different) problem when drawing circles/arcs
Comment 13 Maurizio Paolini 2016-03-23 19:12:45 UTC
Created attachment 98047 [details]
same as previous, but with unmodified kig
Comment 14 Maurizio Paolini 2016-04-01 22:13:39 UTC
A standalone minimal C++ program using Qt5 and drawEllipse shows that the precision
loss with circles having large radius is actually a Qt problem!
I will try to file a qt bug report about this problem.

However I suspect that using drawEllipse in this situation is not the right way to go...
indeed this will cause the creation of a very large Rect and QRectF that will intersect
the visible part in a tiny region.  This *might* entail a big performance loss.

Using drawCurve could be an option (only for circles with big radius), however some adaptation
is required.
Comment 15 Maurizio Paolini 2016-04-01 22:35:44 UTC
Opened a qt bug report:
https://bugreports.qt.io/browse/QTBUG-52312