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 #endif
#ifndef M_PI #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 #endif
#define DL_DXF_MAXLINE 1024 #define DL_DXF_MAXLINE 1024

View File

@ -200,7 +200,7 @@ bool DL_Dxf::readDxfGroups(std::stringstream& stream,
// Read one group of the DXF file and chop the lines: // Read one group of the DXF file and chop the lines:
if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, stream) && if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, stream) &&
DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, stream, false) ) DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, stream, false) )
{ {
groupCode = static_cast<quint32>(toInt(groupCodeTmp)); groupCode = static_cast<quint32>(toInt(groupCodeTmp));
@ -230,7 +230,7 @@ bool DL_Dxf::readDxfGroups(std::stringstream& stream,
* @todo Is it a problem if line is blank (i.e., newline only)? * @todo Is it a problem if line is blank (i.e., newline only)?
* Then, when function returns, (s==NULL). * Then, when function returns, (s==NULL).
*/ */
bool DL_Dxf::getStrippedLine(std::string& s, quint32 size, FILE *fp, bool stripSpace) bool DL_Dxf::getStrippedLine(std::string& s, quint32 size, FILE *fp, bool stripSpace)
{ {
if (!feof(fp)) if (!feof(fp))
{ {
@ -270,7 +270,7 @@ bool DL_Dxf::getStrippedLine(std::string& s, quint32 size, FILE *fp, bool stripS
* Same as above but for stringstreams. * Same as above but for stringstreams.
*/ */
bool DL_Dxf::getStrippedLine(std::string &s, quint32 size, bool DL_Dxf::getStrippedLine(std::string &s, quint32 size,
std::stringstream& stream, bool stripSpace) std::stringstream& stream, bool stripSpace)
{ {
if (!stream.eof()) if (!stream.eof())
@ -312,21 +312,21 @@ bool DL_Dxf::stripWhiteSpace(char** s, bool stripSpace)
// Is last character CR or LF? // Is last character CR or LF?
while ( (lastChar >= 0) && while ( (lastChar >= 0) &&
(((*s)[lastChar] == 10) || ((*s)[lastChar] == 13) || (((*s)[lastChar] == 10) || ((*s)[lastChar] == 13) ||
(stripSpace && ((*s)[lastChar] == ' ' || ((*s)[lastChar] == '\t')))) ) (stripSpace && ((*s)[lastChar] == ' ' || ((*s)[lastChar] == '\t')))) )
{ {
(*s)[lastChar] = '\0'; (*s)[lastChar] = '\0';
lastChar--; lastChar--;
} }
// Skip whitespace, excluding \n, at beginning of line // Skip whitespace, excluding \n, at beginning of line
if (stripSpace) if (stripSpace)
{ {
while ((*s)[0]==' ' || (*s)[0]=='\t') while ((*s)[0]==' ' || (*s)[0]=='\t')
{ {
++(*s); ++(*s);
} }
} }
return ((*s) ? true : false); return ((*s) ? true : false);
} }
@ -1275,7 +1275,7 @@ void DL_Dxf::addEllipse(DL_CreationInterface* creationInterface)
getRealValue(31, 0.0), getRealValue(31, 0.0),
getRealValue(40, 1.0), getRealValue(40, 1.0),
getRealValue(41, 0.0), getRealValue(41, 0.0),
getRealValue(42, 2*M_PI)); getRealValue(42, M_2PI));
creationInterface->addEllipse(d); creationInterface->addEllipse(d);
} }
@ -1395,7 +1395,7 @@ void DL_Dxf::addMText(DL_CreationInterface* creationInterface)
} }
else 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)) else if (hasValue(11) && hasValue(21))
@ -1407,11 +1407,11 @@ void DL_Dxf::addMText(DL_CreationInterface* creationInterface)
{ {
if (y>0.0) if (y>0.0)
{ {
angle = M_PI/2.0; angle = M_PI_2;
} }
else else
{ {
angle = M_PI/2.0*3.0; angle = M_PI_2*3.0;
} }
} }
else else
@ -1481,7 +1481,7 @@ bool DL_Dxf::handleXRecordData(DL_CreationInterface* creationInterface)
if (groupCode<=9 || if (groupCode<=9 ||
groupCode==100 || groupCode==102 || groupCode==105 || groupCode==100 || groupCode==102 || groupCode==105 ||
(groupCode>=300 && groupCode<=369) || (groupCode>=300 && groupCode<=369) ||
(groupCode>=1000 && groupCode<=1009)) (groupCode>=1000 && groupCode<=1009))
{ {
creationInterface->addXRecordString(static_cast<int>(groupCode), groupValue); creationInterface->addXRecordString(static_cast<int>(groupCode), groupValue);
@ -1853,7 +1853,7 @@ void DL_Dxf::addText(DL_CreationInterface* creationInterface)
// style // style
getStringValue(7, ""), getStringValue(7, ""),
// angle // angle
(getRealValue(50, 0.0)*2*M_PI)/360.0); (getRealValue(50, 0.0)*M_2PI)/360.0);
creationInterface->addText(d); creationInterface->addText(d);
} }
@ -1892,7 +1892,7 @@ void DL_Dxf::addAttribute(DL_CreationInterface* creationInterface)
// style // style
getStringValue(7, ""), getStringValue(7, ""),
// angle // angle
(getRealValue(50, 0.0)*2*M_PI)/360.0); (getRealValue(50, 0.0)*M_2PI)/360.0);
creationInterface->addAttribute(d); creationInterface->addAttribute(d);
} }
@ -2272,7 +2272,7 @@ bool DL_Dxf::handleHatchData(DL_CreationInterface* creationInterface)
hatchEdge.defined = true; hatchEdge.defined = true;
return true; return true;
default: default:
break; break;
} }
} }
@ -2291,10 +2291,10 @@ bool DL_Dxf::handleHatchData(DL_CreationInterface* creationInterface)
hatchEdge.radius = toReal(groupValue); hatchEdge.radius = toReal(groupValue);
return true; return true;
case 50: case 50:
hatchEdge.angle1 = toReal(groupValue)/360.0*2*M_PI; hatchEdge.angle1 = toReal(groupValue)/360.0*M_2PI;
return true; return true;
case 51: case 51:
hatchEdge.angle2 = toReal(groupValue)/360.0*2*M_PI; hatchEdge.angle2 = toReal(groupValue)/360.0*M_2PI;
return true; return true;
case 73: case 73:
hatchEdge.ccw = static_cast<bool>(toInt(groupValue)); hatchEdge.ccw = static_cast<bool>(toInt(groupValue));
@ -2326,10 +2326,10 @@ bool DL_Dxf::handleHatchData(DL_CreationInterface* creationInterface)
hatchEdge.ratio = toReal(groupValue); hatchEdge.ratio = toReal(groupValue);
return true; return true;
case 50: case 50:
hatchEdge.angle1 = toReal(groupValue)/360.0*2*M_PI; hatchEdge.angle1 = toReal(groupValue)/360.0*M_2PI;
return true; return true;
case 51: case 51:
hatchEdge.angle2 = toReal(groupValue)/360.0*2*M_PI; hatchEdge.angle2 = toReal(groupValue)/360.0*M_2PI;
return true; return true;
case 73: case 73:
hatchEdge.ccw = static_cast<bool>(toInt(groupValue)); hatchEdge.ccw = static_cast<bool>(toInt(groupValue));
@ -2581,7 +2581,7 @@ void DL_Dxf::writeHeader(DL_WriterA& dw) const
break; break;
case DL_Codes::AC1015: case DL_Codes::AC1015:
dw.dxfString(1, "AC1015"); dw.dxfString(1, "AC1015");
break; break;
case DL_Codes::AC1009_MIN: case DL_Codes::AC1009_MIN:
// minimalistic DXF version is unidentified in file: // minimalistic DXF version is unidentified in file:
break; break;
@ -3050,11 +3050,11 @@ void DL_Dxf::writeInsert(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
if (data.cols!=1 || data.rows!=1) if (data.cols!=1 || data.rows!=1)
{ {
dw.dxfString(100, "AcDbMInsertBlock"); dw.dxfString(100, "AcDbMInsertBlock");
} }
else else
{ {
dw.dxfString(100, "AcDbBlockReference"); dw.dxfString(100, "AcDbBlockReference");
} }
@ -3133,7 +3133,7 @@ void DL_Dxf::writeMText(DL_WriterA& dw,
dw.dxfString(7, data.style); dw.dxfString(7, data.style);
// since dxflib 2.0.2.1: degrees not rad (error in autodesk dxf doc) // 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.dxfInt(73, data.lineSpacingStyle);
dw.dxfReal(44, data.lineSpacingFactor); dw.dxfReal(44, data.lineSpacingFactor);
@ -3165,7 +3165,7 @@ void DL_Dxf::writeText(DL_WriterA& dw,
dw.dxfReal(30, data.ipz); dw.dxfReal(30, data.ipz);
dw.dxfReal(40, data.height); dw.dxfReal(40, data.height);
dw.dxfString(1, data.text); 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.dxfReal(41, data.xScaleFactor);
dw.dxfString(7, data.style); dw.dxfString(7, data.style);
@ -3201,7 +3201,7 @@ void DL_Dxf::writeAttribute(DL_WriterA& dw,
dw.dxfReal(30, data.ipz); dw.dxfReal(30, data.ipz);
dw.dxfReal(40, data.height); dw.dxfReal(40, data.height);
dw.dxfString(1, data.text); 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.dxfReal(41, data.xScaleFactor);
dw.dxfString(7, data.style); dw.dxfString(7, data.style);
@ -3366,7 +3366,7 @@ void DL_Dxf::writeDimLinear(DL_WriterA& dw,
dw.dxfReal(24, edata.dpy2); dw.dxfReal(24, edata.dpy2);
dw.dxfReal(34, 0.0); 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) if (version==DL_VERSION_2000)
{ {
@ -3917,8 +3917,8 @@ void DL_Dxf::writeHatchEdge(DL_WriterA& dw,
dw.dxfReal(10, data.cx); dw.dxfReal(10, data.cx);
dw.dxfReal(20, data.cy); dw.dxfReal(20, data.cy);
dw.dxfReal(40, data.radius); dw.dxfReal(40, data.radius);
dw.dxfReal(50, data.angle1/(2*M_PI)*360.0); dw.dxfReal(50, data.angle1/(M_2PI)*360.0);
dw.dxfReal(51, data.angle2/(2*M_PI)*360.0); dw.dxfReal(51, data.angle2/(M_2PI)*360.0);
dw.dxfInt(73, static_cast<int>((data.ccw))); dw.dxfInt(73, static_cast<int>((data.ccw)));
break; break;
@ -3929,8 +3929,8 @@ void DL_Dxf::writeHatchEdge(DL_WriterA& dw,
dw.dxfReal(11, data.mx); dw.dxfReal(11, data.mx);
dw.dxfReal(21, data.my); dw.dxfReal(21, data.my);
dw.dxfReal(40, data.ratio); dw.dxfReal(40, data.ratio);
dw.dxfReal(50, data.angle1/(2*M_PI)*360.0); dw.dxfReal(50, data.angle1/(M_2PI)*360.0);
dw.dxfReal(51, data.angle2/(2*M_PI)*360.0); dw.dxfReal(51, data.angle2/(M_2PI)*360.0);
dw.dxfInt(73, static_cast<int>((data.ccw))); dw.dxfInt(73, static_cast<int>((data.ccw)));
break; break;
@ -3992,7 +3992,7 @@ int DL_Dxf::writeImage(DL_WriterA& dw,
const DL_Attributes& attrib) const DL_Attributes& attrib)
{ {
/*if (data.file.empty()) /*if (data.file.empty())
{ {
std::cerr << "DL_Dxf::writeImage: " std::cerr << "DL_Dxf::writeImage: "
<< "Image file must not be empty\n"; << "Image file must not be empty\n";
@ -4055,7 +4055,7 @@ void DL_Dxf::writeImageDef(DL_WriterA& dw,
const DL_ImageData& data) const const DL_ImageData& data) const
{ {
/*if (data.file.empty()) /*if (data.file.empty())
{ {
std::cerr << "DL_Dxf::writeImage: " std::cerr << "DL_Dxf::writeImage: "
<< "Image file must not be empty\n"; << "Image file must not be empty\n";
@ -4065,7 +4065,7 @@ void DL_Dxf::writeImageDef(DL_WriterA& dw,
dw.dxfString(0, "IMAGEDEF"); dw.dxfString(0, "IMAGEDEF");
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfHex(5, handle); dw.dxfHex(5, handle);
} }
if (version==DL_VERSION_2000) //-V581 if (version==DL_VERSION_2000) //-V581

View File

@ -39,18 +39,6 @@
#include "dl_entities.h" #include "dl_entities.h"
#include "dl_writer_ascii.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 #ifndef DL_NANDOUBLE
#define DL_NANDOUBLE std::numeric_limits<double>::quiet_NaN() #define DL_NANDOUBLE std::numeric_limits<double>::quiet_NaN()
#endif #endif
@ -132,7 +120,7 @@ public:
DL_CreationInterface* creationInterface); DL_CreationInterface* creationInterface);
static bool getStrippedLine(std::string& s, quint32 size, static bool getStrippedLine(std::string& s, quint32 size,
FILE* stream, bool stripSpace = true); FILE* stream, bool stripSpace = true);
bool readDxfGroups(std::stringstream& stream, bool readDxfGroups(std::stringstream& stream,
DL_CreationInterface* creationInterface); DL_CreationInterface* creationInterface);
bool in(std::stringstream &stream, bool in(std::stringstream &stream,

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)); double da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2));
if (da1 >= M_PI) if (da1 >= M_PI)
{ {
da1 = 2*M_PI - da1; da1 = M_2PI - da1;
} }
if (da1 < m_angle_tolerance) 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)); double da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1));
if (da1 >= M_PI) if (da1 >= M_PI)
{ {
da1 = 2*M_PI - da1; da1 = M_2PI - da1;
} }
if (da1 < m_angle_tolerance) 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); double da2 = fabs(atan2(y4 - y3, x4 - x3) - k);
if (da1 >= M_PI) if (da1 >= M_PI)
{ {
da1 = 2*M_PI - da1; da1 = M_2PI - da1;
} }
if (da2 >= M_PI) if (da2 >= M_PI)
{ {
da2 = 2*M_PI - da2; da2 = M_2PI - da2;
} }
if (da1 + da2 < m_angle_tolerance) if (da1 + da2 < m_angle_tolerance)

View File

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

View File

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

View File

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