From 9e5f333bcc399ab4a3aee6258fd062f9c182ca7d Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 4 Oct 2020 21:43:56 +0200 Subject: [PATCH] Optimize calculations of the angles in DrawArc() Perform calculations in radians to avoid conversions to/from degrees. --- src/common/dcgraph.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index ff53f27331..2e3afe25fe 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -27,12 +27,6 @@ #include "wx/geometry.h" #endif -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -static const double RAD2DEG = 180.0 / M_PI; - //----------------------------------------------------------------------------- // Local functions //----------------------------------------------------------------------------- @@ -686,11 +680,11 @@ void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, double dy = y1 - yc; double radius = sqrt((double)(dx * dx + dy * dy)); wxCoord rad = (wxCoord)radius; - double sa, ea; + double sa, ea; // In radians if (x1 == x2 && y1 == y2) { sa = 0.0; - ea = 360.0; + ea = 2.0 * M_PI; } else if (radius == 0.0) { @@ -699,11 +693,11 @@ void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, else { sa = (x1 - xc == 0) ? - (y1 - yc < 0) ? 90.0 : -90.0 : - -atan2(double(y1 - yc), double(x1 - xc)) * RAD2DEG; + (y1 - yc < 0) ? M_PI / 2.0 : -M_PI / 2.0 : + -atan2(double(y1 - yc), double(x1 - xc)); ea = (x2 - xc == 0) ? - (y2 - yc < 0) ? 90.0 : -90.0 : - -atan2(double(y2 - yc), double(x2 - xc)) * RAD2DEG; + (y2 - yc < 0) ? M_PI / 2.0 : -M_PI / 2.0 : + -atan2(double(y2 - yc), double(x2 - xc)); } bool fill = m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT; @@ -713,7 +707,7 @@ void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, path.MoveToPoint( xc, yc ); // since these angles (ea,sa) are measured counter-clockwise, we invert them to // get clockwise angles - path.AddArc( xc, yc , rad, wxDegToRad(-sa), wxDegToRad(-ea), false ); + path.AddArc( xc, yc , rad, -sa, -ea, false ); if ( fill && ((x1!=x2)||(y1!=y2)) ) path.AddLineToPoint( xc, yc ); m_graphicContext->DrawPath(path);