From edabb010323bfc6f17275abc64c9cb4d4d55609e Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 5 Jun 2016 18:50:54 +0200 Subject: [PATCH] Add initial line segment when adding arc to wxGraphicsPath with GDI+ For the sake of compatibility with Cairo (and Direct2D) an initial line segment should be added to the path from the current point (if set) to the beginning of the arc. Closes #17557 --- interface/wx/graphics.h | 4 ++++ src/msw/graphics.cpp | 25 ++++++++++--------------- src/msw/graphicsd2d.cpp | 5 ++++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index eca9c84f15..0392a43b6f 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -31,11 +31,15 @@ public: The angles are measured in radians but, contrary to the usual mathematical convention, are always @e clockwise from the horizontal axis. + If for clockwise arc @a endAngle is less than @a startAngle it will be progressively increased by 2*pi until it is greater than @a startAngle. If for counter-clockwise arc @a endAngle is greater than @a startAngle it will be progressively decreased by 2*pi until it is less than @a startAngle. + + If there is a current point set, an initial line segment will be added + to the path to connect the current point to the beginning of the arc. */ //@{ virtual void AddArc(wxDouble x, wxDouble y, wxDouble r, diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 16aee51d0b..971c1e34ff 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -1295,7 +1295,7 @@ void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double start { double angle; - // For the sake of consistency normalize angles the same way + // For the sake of compatibility normalize angles the same way // as it is done in Cairo. if ( clockwise ) { @@ -1326,22 +1326,17 @@ void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double start angle = startAngle - endAngle; } - // Native GraphicsPath.AddArc() does nothing when sweep - // angle equals 0 (even current point is not updated) - // so we have to handle this case on our own. + // To ensure compatibility with Cairo an initial + // line segment to the beginning of the arc needs + // to be added to the path. + AddLineToPoint(r*cos(startAngle) + x, r*sin(startAngle) + y); + + // Native GraphicsPath.AddArc() does nothing + // (even current point is not updated) + // when sweep angle equals 0 so we can skip + // any further actions. if ( angle == 0 ) { - wxPoint2DDouble start = wxPoint2DDouble(cos(startAngle) * r, sin(startAngle) * r); - - if (m_figureOpened) - { - AddLineToPoint(start.m_x + x, start.m_y + y); - } - else - { - MoveToPoint(start.m_x + x, start.m_y + y); - } - return; } diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index d58b601a83..01c54b4e17 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -1416,7 +1416,7 @@ void wxD2DPathData::AddArc(wxDouble x, wxDouble y, wxDouble r, wxDouble startAng { double angle; - // For the sake of consistency normalize angles the same way + // For the sake of compatibility normalize angles the same way // as it is done in Cairo. if ( clockwise ) { @@ -1450,6 +1450,9 @@ void wxD2DPathData::AddArc(wxDouble x, wxDouble y, wxDouble r, wxDouble startAng wxPoint2DDouble start = wxPoint2DDouble(cos(startAngle) * r, sin(startAngle) * r); wxPoint2DDouble end = wxPoint2DDouble(cos(endAngle) * r, sin(endAngle) * r); + // To ensure compatibility with Cairo an initial + // line segment to the beginning of the arc needs + // to be added to the path. if (m_figureOpened) { AddLineToPoint(start.m_x + x, start.m_y + y);