Small refactoring. Use M_2PI(2*pi), M_PI_2 (pi/2) and M_PI_4(pi/4) where

possible.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-03-23 13:52:55 +02:00
parent 910dadc871
commit 38dac0ada5
7 changed files with 54 additions and 55 deletions

View File

@ -56,7 +56,16 @@
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_2PI
#define M_2PI 6.28318530717958647692 /* 2*pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
#define DL_DXF_MAXLINE 1024

View File

@ -1275,7 +1275,7 @@ void DL_Dxf::addEllipse(DL_CreationInterface* creationInterface)
getRealValue(31, 0.0),
getRealValue(40, 1.0),
getRealValue(41, 0.0),
getRealValue(42, 2*M_PI));
getRealValue(42, M_2PI));
creationInterface->addEllipse(d);
}
@ -1395,7 +1395,7 @@ void DL_Dxf::addMText(DL_CreationInterface* creationInterface)
}
else
{
angle = (getRealValue(50, 0.0)*2*M_PI)/360.0;
angle = (getRealValue(50, 0.0)*M_2PI)/360.0;
}
}
else if (hasValue(11) && hasValue(21))
@ -1407,11 +1407,11 @@ void DL_Dxf::addMText(DL_CreationInterface* creationInterface)
{
if (y>0.0)
{
angle = M_PI/2.0;
angle = M_PI_2;
}
else
{
angle = M_PI/2.0*3.0;
angle = M_PI_2*3.0;
}
}
else
@ -1853,7 +1853,7 @@ void DL_Dxf::addText(DL_CreationInterface* creationInterface)
// style
getStringValue(7, ""),
// angle
(getRealValue(50, 0.0)*2*M_PI)/360.0);
(getRealValue(50, 0.0)*M_2PI)/360.0);
creationInterface->addText(d);
}
@ -1892,7 +1892,7 @@ void DL_Dxf::addAttribute(DL_CreationInterface* creationInterface)
// style
getStringValue(7, ""),
// angle
(getRealValue(50, 0.0)*2*M_PI)/360.0);
(getRealValue(50, 0.0)*M_2PI)/360.0);
creationInterface->addAttribute(d);
}
@ -2291,10 +2291,10 @@ bool DL_Dxf::handleHatchData(DL_CreationInterface* creationInterface)
hatchEdge.radius = toReal(groupValue);
return true;
case 50:
hatchEdge.angle1 = toReal(groupValue)/360.0*2*M_PI;
hatchEdge.angle1 = toReal(groupValue)/360.0*M_2PI;
return true;
case 51:
hatchEdge.angle2 = toReal(groupValue)/360.0*2*M_PI;
hatchEdge.angle2 = toReal(groupValue)/360.0*M_2PI;
return true;
case 73:
hatchEdge.ccw = static_cast<bool>(toInt(groupValue));
@ -2326,10 +2326,10 @@ bool DL_Dxf::handleHatchData(DL_CreationInterface* creationInterface)
hatchEdge.ratio = toReal(groupValue);
return true;
case 50:
hatchEdge.angle1 = toReal(groupValue)/360.0*2*M_PI;
hatchEdge.angle1 = toReal(groupValue)/360.0*M_2PI;
return true;
case 51:
hatchEdge.angle2 = toReal(groupValue)/360.0*2*M_PI;
hatchEdge.angle2 = toReal(groupValue)/360.0*M_2PI;
return true;
case 73:
hatchEdge.ccw = static_cast<bool>(toInt(groupValue));
@ -3133,7 +3133,7 @@ void DL_Dxf::writeMText(DL_WriterA& dw,
dw.dxfString(7, data.style);
// since dxflib 2.0.2.1: degrees not rad (error in autodesk dxf doc)
dw.dxfReal(50, data.angle/(2.0*M_PI)*360.0);
dw.dxfReal(50, data.angle/(M_2PI)*360.0);
dw.dxfInt(73, data.lineSpacingStyle);
dw.dxfReal(44, data.lineSpacingFactor);
@ -3165,7 +3165,7 @@ void DL_Dxf::writeText(DL_WriterA& dw,
dw.dxfReal(30, data.ipz);
dw.dxfReal(40, data.height);
dw.dxfString(1, data.text);
dw.dxfReal(50, data.angle/(2*M_PI)*360.0);
dw.dxfReal(50, data.angle/(M_2PI)*360.0);
dw.dxfReal(41, data.xScaleFactor);
dw.dxfString(7, data.style);
@ -3201,7 +3201,7 @@ void DL_Dxf::writeAttribute(DL_WriterA& dw,
dw.dxfReal(30, data.ipz);
dw.dxfReal(40, data.height);
dw.dxfString(1, data.text);
dw.dxfReal(50, data.angle/(2*M_PI)*360.0);
dw.dxfReal(50, data.angle/(M_2PI)*360.0);
dw.dxfReal(41, data.xScaleFactor);
dw.dxfString(7, data.style);
@ -3366,7 +3366,7 @@ void DL_Dxf::writeDimLinear(DL_WriterA& dw,
dw.dxfReal(24, edata.dpy2);
dw.dxfReal(34, 0.0);
dw.dxfReal(50, edata.angle/(2.0*M_PI)*360.0);
dw.dxfReal(50, edata.angle/(M_2PI)*360.0);
if (version==DL_VERSION_2000)
{
@ -3917,8 +3917,8 @@ void DL_Dxf::writeHatchEdge(DL_WriterA& dw,
dw.dxfReal(10, data.cx);
dw.dxfReal(20, data.cy);
dw.dxfReal(40, data.radius);
dw.dxfReal(50, data.angle1/(2*M_PI)*360.0);
dw.dxfReal(51, data.angle2/(2*M_PI)*360.0);
dw.dxfReal(50, data.angle1/(M_2PI)*360.0);
dw.dxfReal(51, data.angle2/(M_2PI)*360.0);
dw.dxfInt(73, static_cast<int>((data.ccw)));
break;
@ -3929,8 +3929,8 @@ void DL_Dxf::writeHatchEdge(DL_WriterA& dw,
dw.dxfReal(11, data.mx);
dw.dxfReal(21, data.my);
dw.dxfReal(40, data.ratio);
dw.dxfReal(50, data.angle1/(2*M_PI)*360.0);
dw.dxfReal(51, data.angle2/(2*M_PI)*360.0);
dw.dxfReal(50, data.angle1/(M_2PI)*360.0);
dw.dxfReal(51, data.angle2/(M_2PI)*360.0);
dw.dxfInt(73, static_cast<int>((data.ccw)));
break;

View File

@ -39,18 +39,6 @@
#include "dl_entities.h"
#include "dl_writer_ascii.h"
#ifdef _WIN32
#undef M_PI
#define M_PI 3.14159265358979323846
#if defined(Q_CC_MSVC)
#pragma warning(disable : 4800)
#endif // Q_CC_MSVC
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#ifndef DL_NANDOUBLE
#define DL_NANDOUBLE std::numeric_limits<double>::quiet_NaN()
#endif

View File

@ -346,7 +346,7 @@ void VAbstractCubicBezier::PointBezier_r(qreal x1, qreal y1, qreal x2, qreal y2,
double da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2));
if (da1 >= M_PI)
{
da1 = 2*M_PI - da1;
da1 = M_2PI - da1;
}
if (da1 < m_angle_tolerance)
@ -389,7 +389,7 @@ void VAbstractCubicBezier::PointBezier_r(qreal x1, qreal y1, qreal x2, qreal y2,
double da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1));
if (da1 >= M_PI)
{
da1 = 2*M_PI - da1;
da1 = M_2PI - da1;
}
if (da1 < m_angle_tolerance)
@ -437,11 +437,11 @@ void VAbstractCubicBezier::PointBezier_r(qreal x1, qreal y1, qreal x2, qreal y2,
double da2 = fabs(atan2(y4 - y3, x4 - x3) - k);
if (da1 >= M_PI)
{
da1 = 2*M_PI - da1;
da1 = M_2PI - da1;
}
if (da2 >= M_PI)
{
da2 = 2*M_PI - da2;
da2 = M_2PI - da2;
}
if (da1 + da2 < m_angle_tolerance)

View File

@ -33,6 +33,10 @@
#include "../ifc/ifcdef.h"
#include <QPointF>
#ifndef M_2PI
#define M_2PI 6.28318530717958647692528676655900576
#endif
enum class PathDirection : char { Hide, Show };
class QPainterPath;

View File

@ -377,7 +377,7 @@ void VArc::FindF2(qreal length)
//---------------------------------------------------------------------------------------------------------------------
qreal VArc::MaxLength() const
{
return 2*M_PI*d->radius;
return M_2PI*d->radius;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -32,8 +32,6 @@
#include <QPainterPath>
#include <QtCore/qmath.h>
#define M_2PI 6.28318530717958647692528676655900576
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VSpline default constructor
@ -169,7 +167,7 @@ QVector<QPointF> VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qre
p1pX.setAngle( angle1 );
qreal L = 0, radius = 0, angle = 90;
radius = QLineF(QPointF(p1.x(), p4.y()), p4).length();
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
L = kCurve * radius * 4 / 3 * tan( angle * M_PI_4 / 180.0 );
QLineF p1p2(p1.x(), p1.y(), p1.x() + L * kAsm1, p1.y());
p1p2.setAngle(angle1);
QLineF p4p3(p4.x(), p4.y(), p4.x() + L * kAsm2, p4.y());