use wxIsSameDouble() and wxIsNullDouble() for warning-less double comparison of doubles

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-09-25 23:27:27 +00:00
parent f1afd2e066
commit c77a67962c
14 changed files with 139 additions and 127 deletions

View File

@@ -81,7 +81,7 @@ bool wxTransformMatrix::operator == (const wxTransformMatrix& mat) const
{
for (j = 0; j < 3; j++)
{
if (m_matrix[i][j] != mat.m_matrix[i][j])
if ( !wxIsSameDouble(m_matrix[i][j], mat.m_matrix[i][j]) )
return false;
}
}
@@ -129,27 +129,22 @@ bool wxTransformMatrix::Invert(void)
// now divide by the determinant
double det = m_matrix[0][0] * inverseMatrix[0][0] + m_matrix[0][1] * inverseMatrix[1][0] + m_matrix[0][2] * inverseMatrix[2][0];
if (det != 0.0)
{
inverseMatrix[0][0] /= det; inverseMatrix[1][0] /= det; inverseMatrix[2][0] /= det;
inverseMatrix[0][1] /= det; inverseMatrix[1][1] /= det; inverseMatrix[2][1] /= det;
inverseMatrix[0][2] /= det; inverseMatrix[1][2] /= det; inverseMatrix[2][2] /= det;
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
m_matrix[i][j] = inverseMatrix[i][j];
}
}
m_isIdentity = IsIdentity1();
return true;
}
else
{
if ( wxIsNullDouble(det) )
return false;
inverseMatrix[0][0] /= det; inverseMatrix[1][0] /= det; inverseMatrix[2][0] /= det;
inverseMatrix[0][1] /= det; inverseMatrix[1][1] /= det; inverseMatrix[2][1] /= det;
inverseMatrix[0][2] /= det; inverseMatrix[1][2] /= det; inverseMatrix[2][2] /= det;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
m_matrix[i][j] = inverseMatrix[i][j];
}
}
m_isIdentity = IsIdentity1();
return true;
}
// Make into identity matrix
@@ -195,8 +190,8 @@ wxTransformMatrix& wxTransformMatrix::Scale(const double &xs, const double &ys,
if (m_isIdentity)
{
double tx =xc*(1-xs);
double ty =yc*(1-ys);
double tx = xc*(1-xs);
double ty = yc*(1-ys);
r00 = xs;
r10 = 0;
r20 = tx;
@@ -204,10 +199,10 @@ wxTransformMatrix& wxTransformMatrix::Scale(const double &xs, const double &ys,
r11 = ys;
r21 = ty;
}
else if (xc!=0 || yc!=0)
else if ( !wxIsNullDouble(xc) || !wxIsNullDouble(yc) )
{
double tx =xc*(1-xs);
double ty =yc*(1-ys);
double tx = xc*(1-xs);
double ty = yc*(1-ys);
r00 = xs * m_matrix[0][0];
r10 = xs * m_matrix[1][0];
r20 = xs * m_matrix[2][0] + tx;
@@ -320,8 +315,8 @@ wxTransformMatrix& wxTransformMatrix::Rotate(const double &degrees, const doubl
if (m_isIdentity)
{
double tx = x*(1-c)+y*s;
double ty = y*(1-c)-x*s;
double tx = x*(1-c)+y*s;
double ty = y*(1-c)-x*s;
r00 = c ;
r10 = -s;
r20 = tx;
@@ -329,10 +324,10 @@ wxTransformMatrix& wxTransformMatrix::Rotate(const double &degrees, const doubl
r11 = c;
r21 = ty;
}
else if (x!=0 || y!=0)
else if ( !wxIsNullDouble(x) || !wxIsNullDouble(y) )
{
double tx = x*(1-c)+y*s;
double ty = y*(1-c)-x*s;
double tx = x*(1-c)+y*s;
double ty = y*(1-c)-x*s;
r00 = c * m_matrix[0][0] - s * m_matrix[0][1] + tx * m_matrix[0][2];
r10 = c * m_matrix[1][0] - s * m_matrix[1][1] + tx * m_matrix[1][2];
r20 = c * m_matrix[2][0] - s * m_matrix[2][1] + tx;// * m_matrix[2][2];
@@ -404,15 +399,15 @@ bool wxTransformMatrix::InverseTransformPoint(double x, double y, double& tx, do
{
if (IsIdentity())
{
tx = x; ty = y; return true;
tx = x;
ty = y;
return true;
}
double z = (1.0 - m_matrix[0][2] * x - m_matrix[1][2] * y) / m_matrix[2][2];
if (z == 0.0)
{
// z = 0.0000001;
const double z = (1.0 - m_matrix[0][2] * x - m_matrix[1][2] * y) / m_matrix[2][2];
if ( wxIsNullDouble(z) )
return false;
}
tx = x * m_matrix[0][0] + y * m_matrix[1][0] + z * m_matrix[2][0];
ty = x * m_matrix[0][1] + y * m_matrix[1][1] + z * m_matrix[2][1];
return true;
@@ -556,7 +551,7 @@ double wxTransformMatrix::Get_scaleX()
{
double scale_factor;
double rot_angle = CheckInt(atan2(m_matrix[1][0],m_matrix[0][0])*180/pi);
if (rot_angle != 90 && rot_angle != -90)
if ( !wxIsSameDouble(rot_angle, 90) && !wxIsSameDouble(rot_angle, -90) )
scale_factor = m_matrix[0][0]/cos((rot_angle/180)*pi);
else
scale_factor = m_matrix[0][0]/sin((rot_angle/180)*pi); // er kan nl. niet door 0 gedeeld worden !
@@ -572,7 +567,7 @@ double wxTransformMatrix::Get_scaleY()
{
double scale_factor;
double rot_angle = CheckInt(atan2(m_matrix[1][0],m_matrix[0][0])*180/pi);
if (rot_angle != 90 && rot_angle != -90)
if ( !wxIsSameDouble(rot_angle, 90) && !wxIsSameDouble(rot_angle, -90) )
scale_factor = m_matrix[1][1]/cos((rot_angle/180)*pi);
else
scale_factor = m_matrix[1][1]/sin((rot_angle/180)*pi); // er kan nl. niet door 0 gedeeld worden !