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.kaganski@collabora.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user