Fixed "comparing floating point with == is unsafe"

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2015-10-02 05:46:10 +03:00
parent 55ab727d78
commit 0b16f5acf0
3 changed files with 23 additions and 6 deletions

View File

@ -34,4 +34,20 @@ enum class VarMeasurement : unsigned char { English=0, Metric=1 };
//Default drawing units for AutoCAD DesignCenter blocks: //Default drawing units for AutoCAD DesignCenter blocks:
enum class VarInsunits : unsigned char { Inches=1, Millimeters=4, Centimeters=5 }; enum class VarInsunits : unsigned char { Inches=1, Millimeters=4, Centimeters=5 };
static inline bool DL_FuzzyComparePossibleNulls(double p1, double p2)
{
if(qFuzzyIsNull(p1))
{
return qFuzzyIsNull(p2);
}
else if(qFuzzyIsNull(p2))
{
return false;
}
else
{
return qFuzzyCompare(p1, p2);
}
}
#endif // DXFDEF_H #endif // DXFDEF_H

View File

@ -3089,13 +3089,13 @@ void DL_Dxf::writeInsert(DL_WriterA& dw,
dw.dxfReal(10, data.ipx); dw.dxfReal(10, data.ipx);
dw.dxfReal(20, data.ipy); dw.dxfReal(20, data.ipy);
dw.dxfReal(30, data.ipz); dw.dxfReal(30, data.ipz);
if (data.sx!=1.0 || data.sy!=1.0) if (!DL_FuzzyComparePossibleNulls(data.sx, 1.0) || !DL_FuzzyComparePossibleNulls(data.sy, 1.0))
{ {
dw.dxfReal(41, data.sx); dw.dxfReal(41, data.sx);
dw.dxfReal(42, data.sy); dw.dxfReal(42, data.sy);
dw.dxfReal(43, 1.0); dw.dxfReal(43, 1.0);
} }
if (data.angle!=0.0) if (!DL_FuzzyComparePossibleNulls(data.angle, 0.0))
{ {
dw.dxfReal(50, data.angle); dw.dxfReal(50, data.angle);
} }
@ -3104,7 +3104,7 @@ void DL_Dxf::writeInsert(DL_WriterA& dw,
dw.dxfInt(70, data.cols); dw.dxfInt(70, data.cols);
dw.dxfInt(71, data.rows); dw.dxfInt(71, data.rows);
} }
if (data.colSp!=0.0 || data.rowSp!=0.0) if (!DL_FuzzyComparePossibleNulls(data.colSp, 0.0) || !DL_FuzzyComparePossibleNulls(data.rowSp, 0.0))
{ {
dw.dxfReal(44, data.colSp); dw.dxfReal(44, data.colSp);
dw.dxfReal(45, data.rowSp); dw.dxfReal(45, data.rowSp);

View File

@ -26,6 +26,7 @@
#define DL_ENTITIES_H #define DL_ENTITIES_H
#include "dl_global.h" #include "dl_global.h"
#include "dxfdef.h"
#include <string> #include <string>
#include <vector> #include <vector>
@ -168,9 +169,9 @@ struct DXFLIB_EXPORT DL_StyleData
// ignore lastHeightUsed: // ignore lastHeightUsed:
return (name==other.name && return (name==other.name &&
flags==other.flags && flags==other.flags &&
fixedTextHeight==other.fixedTextHeight && DL_FuzzyComparePossibleNulls(fixedTextHeight, other.fixedTextHeight) &&
widthFactor==other.widthFactor && DL_FuzzyComparePossibleNulls(widthFactor, other.widthFactor) &&
obliqueAngle==other.obliqueAngle && DL_FuzzyComparePossibleNulls(obliqueAngle, other.obliqueAngle) &&
textGenerationFlags==other.textGenerationFlags && textGenerationFlags==other.textGenerationFlags &&
primaryFontFile==other.primaryFontFile && primaryFontFile==other.primaryFontFile &&
bigFontFile==other.bigFontFile); bigFontFile==other.bigFontFile);