Problem Drawing Arcs to wxPDFDC

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
rsb
Experienced Solver
Experienced Solver
Posts: 78
Joined: Fri May 29, 2015 7:26 pm

Problem Drawing Arcs to wxPDFDC

Postby rsb » Mon Mar 20, 2017 8:24 pm

Hello,

I'm drawing an arc using a wxDC object and it looks fine, (first picture). However,
when I draw the same arc using a wxPDFDC object, it's not right (second picture).
In the pictures, there are two arcs, the arc to the left of the plus sign in the first
picture is wrong in the PDF document.

DCArc.PNG
DCArc.PNG (1.96 KiB) Viewed 108 times

PDFArc.PNG
PDFArc.PNG (2.29 KiB) Viewed 108 times


Any idea what wrong?

wxWidgets 3.1.0
wxPdfDocument 0.9.5
Windows 7
VS2015

Thanks very much.

utelle
Moderator
Moderator
Posts: 727
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problem Drawing Arcs to wxPDFDC

Postby utelle » Mon Mar 20, 2017 9:37 pm

rsb wrote:I'm drawing an arc using a wxDC object and it looks fine, (first picture). However,
when I draw the same arc using a wxPDFDC object, it's not right (second picture).
In the pictures, there are two arcs, the arc to the left of the plus sign in the first
picture is wrong in the PDF document.

Could you please provide the code you use to draw the arcs? This would help to analyze the problem. Thanks.

Regards,

Ulrich

rsb
Experienced Solver
Experienced Solver
Posts: 78
Joined: Fri May 29, 2015 7:26 pm

Re: Problem Drawing Arcs to wxPDFDC

Postby rsb » Mon Mar 20, 2017 9:56 pm

Hope this is good enough:

if( start_angle < end_angle )
{
if( start_angle <= mid_angle && mid_angle <= end_angle )
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
}
else
{
if( end_angle <= mid_angle && mid_angle <= start_angle )
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
}

Start, mid and end angles are determined using:

start angle --> atan2((double) start.y - center.y,(double) start.x - center.x))
mid angle --> atan2((double) mid.y - center.y,(double) mid.x - center.x))
end angle --> atan2((double) end.y - center.y,(double) end.x - center.x))

Thanks.

utelle
Moderator
Moderator
Posts: 727
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problem Drawing Arcs to wxPDFDC

Postby utelle » Tue Mar 21, 2017 7:32 am

rsb wrote:Hope this is good enough:

if( start_angle < end_angle )
{
if( start_angle <= mid_angle && mid_angle <= end_angle )
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
}
else
{
if( end_angle <= mid_angle && mid_angle <= start_angle )
dc.DrawArc(endPoint.x, endPoint.y, startPoint.x, startPoint.y, centerPoint.x, centerPoint.y);
else
dc.DrawArc(startPoint.x, startPoint.y, endPoint.x, endPoint.y, centerPoint.x, centerPoint.y);
}

Start, mid and end angles are determined using:

start angle --> atan2((double) start.y - center.y,(double) start.x - center.x))
mid angle --> atan2((double) mid.y - center.y,(double) mid.x - center.x))
end angle --> atan2((double) end.y - center.y,(double) end.x - center.x))

Thanks.

Your given code draws only exactly 1 arc. Is the same code used to draw both arcs? If yes, you need 2 sets of points for start, mid, end, and center. I have no clue whether both sets share the same mid point or not, and how you derived the center points. Could you please provide a sample set of points showing the observed behaviour?

Obviously the problem has something to do with how the drawing direction of the arc is derived from the angles.

Regards,

Ulrich

utelle
Moderator
Moderator
Posts: 727
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problem Drawing Arcs to wxPDFDC

Postby utelle » Thu Mar 23, 2017 4:48 pm

Although I doubt that your code works correctly as given (I experienced always the wrong drawing direction on screen), I applied a small fix to the wxPdfDC implementation that hopefully fixes your problem without introducing new ones. Please download the current source code from wxPdfDocument at github and give it a try.

Regards,

Ulrich

rsb
Experienced Solver
Experienced Solver
Posts: 78
Joined: Fri May 29, 2015 7:26 pm

Re: Problem Drawing Arcs to wxPDFDC

Postby rsb » Tue Mar 28, 2017 8:54 pm

Thanks, That did fix the initial problem I listed, however, It didn't fix everything.

Here's a test case that we use. The first image is the Screen DC,
The second is the PDF DC before your fix, the third is the PDF DC
after your fix.

You can see that two of the four arcs now display correctly, but two are still wrong.

ArcsWxDC.PNG
ArcsWxDC.PNG (8.72 KiB) Viewed 24 times
ArcsPDFBeforeFix.PNG
ArcsPDFBeforeFix.PNG (2.14 KiB) Viewed 24 times
ArcsPDFAfterFix.PNG
ArcsPDFAfterFix.PNG (3.92 KiB) Viewed 24 times


Thanks very much.


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 1 guest