hwpfilter/source/hcode.cxx | 18 ++--------- hwpfilter/source/hwpreader.cxx | 45 +++++++++++++--------------- lotuswordpro/inc/xfilter/xfdrawobj.hxx | 3 + lotuswordpro/inc/xfilter/xfglobal.hxx | 2 - lotuswordpro/source/filter/lwpdrawobj.cxx | 3 + scaddins/source/analysis/analysis.cxx | 2 - scaddins/source/analysis/analysishelper.hxx | 6 --- 7 files changed, 33 insertions(+), 46 deletions(-)
New commits: commit 35c85effecb5a615a361c1b7d92d08447bc83423 Author: Hossein <hoss...@libreoffice.org> AuthorDate: Thu Nov 11 00:00:38 2021 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Nov 14 08:14:15 2021 +0100 Use M_PI instead of defined value; use rad2deg() * Replace defined values of PI with M_PI defined in <cmath> * Use M_PI_2 instead of PI / 2.0 * Instances could be found with: git grep 3.14 *.cxx *.hxx|grep define * One instance is ignored: sc/source/core/opencl/opinlinefun_statistical.cxx * Replace *(180 / PI) with basegfx::rad2deg() * Replace 2*PI/360 with basegfx::deg2rad() * Use atan2 instead of atan where it was more appropriate + atan2() handles all 4 quadrants + Extra conditions for different quadrants are removed Change-Id: I083ee2e1427cd36ba0b8c38e4fe5f782d6486075 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124229 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx index ff133cebd25a..514e594a2c49 100644 --- a/hwpfilter/source/hcode.cxx +++ b/hwpfilter/source/hcode.cxx @@ -24,17 +24,16 @@ * Special johap code => ks code => unicode */ #include "precompile.h" +#include <basegfx/numeric/ftools.hxx> #include <sal/types.h> #include <sal/macros.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> +#include <cmath> #include "hcode.h" #include "ksc5601.h" -#define PI 3.14159265358979323846 - static hchar jaso2ks(hchar hh); // ccvHH2ASC code convert HWP20 to ASC(KSSM) @@ -1445,17 +1444,8 @@ double calcAngle(int x1, int y1, int x2, int y2) return 270.; } double angle; - angle = (180 / PI) * atan( ( y2 - y1 ) * 1.0 / ( x2 - x1 )); - if( y2 >= y1 ){ /* 1, 2 quadrant */ - if( angle < 0. ) - angle += 180.; - } - else{ /* 3, 4 quadrants */ - if( angle > 0 ) - angle += 180.; - else - angle += 360.; - } + // atan2 handles all 4 quadrants + angle = basegfx::rad2deg(atan2(y2 - y1 , x2 - x1)); return angle; } diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index 43f48d535a0a..54684bb51eec 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -22,11 +22,12 @@ #include <string_view> #include "hwpreader.hxx" -#include <math.h> +#include <cmath> #include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <tools/stream.hxx> +#include <basegfx/numeric/ftools.hxx> #include "fontmap.hxx" #include "formula.h" @@ -50,8 +51,6 @@ #define WTMM(x) (static_cast<double>(x) / 1800. * 25.4) // unit => mm #define WTSM(x) (static_cast<int>((x) / 1800. * 2540)) // unit ==> 1/100 mm -#define PI 3.14159265358979323846 - // xmloff/xmlkyd.hxx constexpr OUStringLiteral sXML_CDATA = u"CDATA"; @@ -4049,14 +4048,14 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) /* 2 - rotation angle calculation */ if( pt[1].x == pt[0].x ){ if( pt[1].y > pt[0].y ) - rotate = PI/2; + rotate = M_PI_2; else - rotate = -(PI/2); + rotate = -M_PI_2; } else rotate = atan(static_cast<double>( pt[1].y - pt[0].y )/(pt[1].x - pt[0].x )); if( pt[1].x < pt[0].x ) - rotate += PI; + rotate += M_PI; for( i = 0 ; i < 3 ; i++){ r_pt[i].x = static_cast<int>(pt[i].x * cos(-rotate) - pt[i].y * sin(-rotate)); @@ -4068,10 +4067,10 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) skewX = 0; else skewX = atan(static_cast<double>(r_pt[2].x - r_pt[1].x )/( r_pt[2].y - r_pt[1].y )); - if( skewX >= PI/2 ) - skewX -= PI; - if( skewX <= -PI/2 ) - skewX += PI; + if( skewX >= M_PI_2 ) + skewX -= M_PI; + if( skewX <= -M_PI_2 ) + skewX += M_PI; OUString trans; if( skewX != 0.0 && rotate != 0.0 ){ @@ -4264,38 +4263,38 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox) if( pal->pt[1].x == pal->pt[0].x ){ if( pal->pt[0].y < pal->pt[1].y ) - start_angle = 1.5 * PI; + start_angle = 3 * M_PI_2; else - start_angle = 0.5 * PI; + start_angle = M_PI_2; } else{ start_angle = atan(static_cast<double>( pal->pt[0].y - pal->pt[1].y )/( pal->pt[1].x - pal->pt[0].x )); if( pal->pt[1].x < pal->pt[0].x ) - start_angle += PI; + start_angle += M_PI; } if( pal->pt[1].x == pal->pt[2].x ){ if( pal->pt[2].y < pal->pt[1].y ) - end_angle = 1.5 * PI; + end_angle = 3 * M_PI_2; else - end_angle = 0.5 * PI; + end_angle = M_PI_2; } else{ end_angle = atan(static_cast<double>( pal->pt[2].y - pal->pt[1].y )/( pal->pt[1].x - pal->pt[2].x )); if( pal->pt[1].x < pal->pt[2].x ) - end_angle += PI; + end_angle += M_PI; } - if( start_angle >= 2 * PI ) - start_angle -= 2 * PI; - if( end_angle >= 2 * PI ) - end_angle -= 2 * PI; - if( ( start_angle > end_angle ) && (start_angle - end_angle < PI )){ + if( start_angle >= 2 * M_PI ) + start_angle -= 2 * M_PI; + if( end_angle >= 2 * M_PI ) + end_angle -= 2 * M_PI; + if( ( start_angle > end_angle ) && (start_angle - end_angle < M_PI )){ double tmp_angle = start_angle; start_angle = end_angle; end_angle = tmp_angle; } - padd("draw:start-angle", sXML_CDATA, Double2Str(start_angle * 180. / PI)); - padd("draw:end-angle", sXML_CDATA, Double2Str(end_angle * 180. / PI)); + padd("draw:start-angle", sXML_CDATA, Double2Str(basegfx::rad2deg(start_angle))); + padd("draw:end-angle", sXML_CDATA, Double2Str(basegfx::rad2deg(end_angle))); } else diff --git a/lotuswordpro/inc/xfilter/xfdrawobj.hxx b/lotuswordpro/inc/xfilter/xfdrawobj.hxx index c18058adedad..66464fa1f86d 100644 --- a/lotuswordpro/inc/xfilter/xfdrawobj.hxx +++ b/lotuswordpro/inc/xfilter/xfdrawobj.hxx @@ -62,6 +62,7 @@ #include <xfilter/xfglobal.hxx> #include <xfilter/xfframe.hxx> +#include <basegfx/numeric/ftools.hxx> #define XFDRAWOBJECT_FLAG_ROTATE 0X00000001 #define XFDRAWOBJECT_FLAG_TRANSLATE 0X00000002 @@ -89,7 +90,7 @@ public: void SetRotate(double degree) { m_nDrawFlag |= XFDRAWOBJECT_FLAG_ROTATE; - m_fRotate = degree*2*PI/360; + m_fRotate = basegfx::deg2rad(degree); m_aRotatePoint = XFPoint(0,0); } diff --git a/lotuswordpro/inc/xfilter/xfglobal.hxx b/lotuswordpro/inc/xfilter/xfglobal.hxx index 247ae9dd5836..60f1a798c588 100644 --- a/lotuswordpro/inc/xfilter/xfglobal.hxx +++ b/lotuswordpro/inc/xfilter/xfglobal.hxx @@ -62,8 +62,8 @@ #define INCLUDED_LOTUSWORDPRO_INC_XFILTER_XFGLOBAL_HXX #include <rtl/ustring.hxx> +#include <cmath> -#define PI 3.1415926 #define FLOAT_MIN 0.001 #define MAX2(a, b) (((a) > (b)) ? (a) : (b)) #define MAX3(a, b, c) MAX2(a, MAX2(b, c)) diff --git a/lotuswordpro/source/filter/lwpdrawobj.cxx b/lotuswordpro/source/filter/lwpdrawobj.cxx index 547017a68555..5245bfd93ddc 100644 --- a/lotuswordpro/source/filter/lwpdrawobj.cxx +++ b/lotuswordpro/source/filter/lwpdrawobj.cxx @@ -63,6 +63,7 @@ #include "lwpdrawobj.hxx" #include <lwptools.hxx> #include <tools/stream.hxx> +#include <basegfx/numeric/ftools.hxx> #include <xfilter/xfframe.hxx> @@ -796,7 +797,7 @@ XFFrame* LwpDrawRectangle::CreateStandardDrawObj(const OUString& rStyleName) if (aSdwRect.IsRectRotated()) { - pRect->SetRotate( fRotAngle / PI * 180);// aXFCenter); + pRect->SetRotate( basegfx::rad2deg(fRotAngle) );// aXFCenter); } pRect->SetStyleName(rStyleName); diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx index dca1c370d994..9ad63bc15efa 100644 --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -561,7 +561,7 @@ double SAL_CALL AnalysisAddIn::getMround( double fNum, double fMult ) double SAL_CALL AnalysisAddIn::getSqrtpi( double fNum ) { - double fRet = sqrt( fNum * PI ); + double fRet = sqrt( fNum * M_PI ); RETURN_FINITE( fRet ); } diff --git a/scaddins/source/analysis/analysishelper.hxx b/scaddins/source/analysis/analysishelper.hxx index 7e0610493929..093d939301eb 100644 --- a/scaddins/source/analysis/analysishelper.hxx +++ b/scaddins/source/analysis/analysishelper.hxx @@ -22,7 +22,7 @@ #include <com/sun/star/uno/Reference.hxx> #include <unotools/resmgr.hxx> -#include <math.h> +#include <cmath> #include <memory> #include <vector> @@ -35,10 +35,6 @@ namespace sca::analysis { class ScaAnyConverter; - -#define PI 3.1415926535897932 - - inline bool IsLeapYear( sal_uInt16 nYear ); #ifdef DISABLE_DYNLOADING