From eb2fc93a9b1e3b7b789b492f038cd34086bc477d Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 29 May 2016 17:39:03 +0200 Subject: [PATCH] Fixed adding arc to wxGraphicsPath with Direct2D renderer Modified calculations of sweep angle to get its correct value for all combinations of start/end angle values and clockwise/counter-clockwise drawing. See #17552 --- src/msw/graphicsd2d.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 601cf40b99..4befc60c70 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -1428,31 +1428,33 @@ void wxD2DPathData::AddArc(wxDouble x, wxDouble y, wxDouble r, wxDouble startAng } double angle = (end.GetVectorAngle() - start.GetVectorAngle()); - - if (!clockwise) + if ( angle == 360 || angle == -360 ) { - angle = 360 - angle; + AddCircle(center.m_x, center.m_y, r); + return; } + if ( !clockwise ) + angle = -angle; + + if ( angle < 0 ) + angle += 360; + while (abs(angle) > 360) { angle -= (angle / abs(angle)) * 360; } - if (angle == 360) - { - AddCircle(center.m_x, center.m_y, start.GetVectorLength()); - return; - } + D2D1_SWEEP_DIRECTION sweepDirection = clockwise ? + D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE; - D2D1_SWEEP_DIRECTION sweepDirection = clockwise ? D2D1_SWEEP_DIRECTION_CLOCKWISE : D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE; - - D2D1_ARC_SIZE arcSize = angle > 180 ? D2D1_ARC_SIZE_LARGE : D2D1_ARC_SIZE_SMALL; + D2D1_ARC_SIZE arcSize = angle > 180 ? + D2D1_ARC_SIZE_LARGE : D2D1_ARC_SIZE_SMALL; D2D1_ARC_SEGMENT arcSegment = { - { (FLOAT)(end.m_x + x), (FLOAT)(end.m_y + y) }, // end point - { (FLOAT)r, (FLOAT) r }, // size - 0, // rotation + D2D1::Point2((FLOAT)(end.m_x + x), (FLOAT)(end.m_y + y)), // end point + D2D1::SizeF((FLOAT)r, (FLOAT)r), // size + 0.0f, // rotation sweepDirection, // sweep direction arcSize // arc size };