summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2021-11-11 00:00:38 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2021-11-14 08:14:15 +0100
commit35c85effecb5a615a361c1b7d92d08447bc83423 (patch)
tree360d042d2499acdc2e2b7fb3017f3d2db0829b92 /hwpfilter
parent4d4278b1403d38b34ff80ca2a92164f40abd9c36 (diff)
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>
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hcode.cxx18
-rw-r--r--hwpfilter/source/hwpreader.cxx45
2 files changed, 26 insertions, 37 deletions
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