From 1f3d2389bc89bf058577e27a9a707dab12f73cdb Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 16 Sep 2019 17:59:18 +0200 Subject: [PATCH] start to replace old C-style casts with static_cast or reinterpret_cast, avoid implicit casts --- src/Base/BoundBox.h | 4 +- src/Base/Builder3D.cpp | 12 +-- src/Base/Factory.cpp | 2 +- src/Base/GeometryPyCXX.h | 6 +- src/Base/Handle.cpp | 4 +- src/Base/Matrix.cpp | 222 +++++++++------------------------------ src/Base/Matrix.h | 55 ++++++---- src/Base/Rotation.cpp | 66 ++++++------ src/Base/Vector3D.h | 6 +- src/Base/XMLTools.h | 4 +- 10 files changed, 136 insertions(+), 245 deletions(-) diff --git a/src/Base/BoundBox.h b/src/Base/BoundBox.h index 48285fc07a..3fe9ca9294 100644 --- a/src/Base/BoundBox.h +++ b/src/Base/BoundBox.h @@ -419,7 +419,7 @@ inline bool BoundBox3<_Precision>::GetOctantFromVector (const Vector3<_Precision usNdx |= 2; if (isOnRayS ((MinZ + MaxZ)/2, MaxZ, rclVct.z)) // back/FRONT usNdx |= 4; - rclOctant = (OCTANT) usNdx; + rclOctant = static_cast(usNdx); return true; } @@ -615,7 +615,7 @@ inline bool BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision> // does intersection point lie in desired direction // or was found the opposing side? // -> scalar product of both direction vectors > 0 (angle < 90) - rc = ((cVctRes - rcVct) * rcVctDir) >= (_Precision)0.0; + rc = ((cVctRes - rcVct) * rcVctDir) >= 0.0; } } } diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index 4bc67b50f0..d152065d05 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -274,9 +274,9 @@ void Builder3D::addTransformation(const Base::Matrix4D& transform) Base::Vector3f cAxis, cBase; float fAngle, fTranslation; transform.toAxisAngle(cBase, cAxis,fAngle,fTranslation); - cBase.x = (float)transform[0][3]; - cBase.y = (float)transform[1][3]; - cBase.z = (float)transform[2][3]; + cBase.x = static_cast(transform[0][3]); + cBase.y = static_cast(transform[1][3]); + cBase.z = static_cast(transform[2][3]); addTransformation(cBase,cAxis,fAngle); } @@ -896,9 +896,9 @@ void InventorBuilder::addTransformation(const Matrix4D& transform) Vector3f cAxis, cBase; float fAngle, fTranslation; transform.toAxisAngle(cBase, cAxis,fAngle,fTranslation); - cBase.x = (float)transform[0][3]; - cBase.y = (float)transform[1][3]; - cBase.z = (float)transform[2][3]; + cBase.x = static_cast(transform[0][3]); + cBase.y = static_cast(transform[1][3]); + cBase.z = static_cast(transform[2][3]); addTransformation(cBase,cAxis,fAngle); } diff --git a/src/Base/Factory.cpp b/src/Base/Factory.cpp index 4c9f80a1bf..34fe012ac5 100644 --- a/src/Base/Factory.cpp +++ b/src/Base/Factory.cpp @@ -97,7 +97,7 @@ void ScriptFactorySingleton::Destruct (void) const char* ScriptFactorySingleton::ProduceScript (const char* sScriptName) const { - const char* script = (const char*)Produce(sScriptName); + const char* script = static_cast(Produce(sScriptName)); if ( !script ) { diff --git a/src/Base/GeometryPyCXX.h b/src/Base/GeometryPyCXX.h index 6003b9735e..8226918845 100644 --- a/src/Base/GeometryPyCXX.h +++ b/src/Base/GeometryPyCXX.h @@ -41,9 +41,9 @@ template inline Vector3 getVectorFromTuple(PyObject* o) { Py::Sequence tuple(o); - T x = (T)Py::Float(tuple.getItem(0)); - T y = (T)Py::Float(tuple.getItem(1)); - T z = (T)Py::Float(tuple.getItem(2)); + T x = static_cast(Py::Float(tuple.getItem(0))); + T y = static_cast(Py::Float(tuple.getItem(1))); + T z = static_cast(Py::Float(tuple.getItem(2))); return Vector3(x,y,z); } diff --git a/src/Base/Handle.cpp b/src/Base/Handle.cpp index f8ba0982bb..2e64d0b003 100644 --- a/src/Base/Handle.cpp +++ b/src/Base/Handle.cpp @@ -47,7 +47,7 @@ Handled::Handled() Handled::~Handled() { - if ((int)(*_lRefCount) != 0) + if (static_cast(*_lRefCount) != 0) std::cerr << "Reference counter of deleted object is not zero!!!!!" << std::endl; delete _lRefCount; } @@ -67,7 +67,7 @@ void Handled::unref() const int Handled::getRefCount(void) const { - return (int)(*_lRefCount); + return static_cast(*_lRefCount); } const Handled& Handled::operator = (const Handled&) diff --git a/src/Base/Matrix.cpp b/src/Base/Matrix.cpp index c1c32ea5f1..c8a009c9c1 100644 --- a/src/Base/Matrix.cpp +++ b/src/Base/Matrix.cpp @@ -30,6 +30,7 @@ #include "Matrix.h" +#include "Converter.h" using namespace Base; @@ -43,10 +44,22 @@ Matrix4D::Matrix4D (float a11, float a12, float a13, float a14, float a31, float a32, float a33, float a34, float a41, float a42, float a43, float a44 ) { - dMtrx4D[0][0] = a11; dMtrx4D[0][1] = a12; dMtrx4D[0][2] = a13; dMtrx4D[0][3] = a14; - dMtrx4D[1][0] = a21; dMtrx4D[1][1] = a22; dMtrx4D[1][2] = a23; dMtrx4D[1][3] = a24; - dMtrx4D[2][0] = a31; dMtrx4D[2][1] = a32; dMtrx4D[2][2] = a33; dMtrx4D[2][3] = a34; - dMtrx4D[3][0] = a41; dMtrx4D[3][1] = a42; dMtrx4D[3][2] = a43; dMtrx4D[3][3] = a44; + dMtrx4D[0][0] = static_cast(a11); + dMtrx4D[0][1] = static_cast(a12); + dMtrx4D[0][2] = static_cast(a13); + dMtrx4D[0][3] = static_cast(a14); + dMtrx4D[1][0] = static_cast(a21); + dMtrx4D[1][1] = static_cast(a22); + dMtrx4D[1][2] = static_cast(a23); + dMtrx4D[1][3] = static_cast(a24); + dMtrx4D[2][0] = static_cast(a31); + dMtrx4D[2][1] = static_cast(a32); + dMtrx4D[2][2] = static_cast(a33); + dMtrx4D[2][3] = static_cast(a34); + dMtrx4D[3][0] = static_cast(a41); + dMtrx4D[3][1] = static_cast(a42); + dMtrx4D[3][2] = static_cast(a43); + dMtrx4D[3][3] = static_cast(a44); } Matrix4D::Matrix4D (double a11, double a12, double a13, double a14, @@ -114,9 +127,7 @@ double Matrix4D::determinant() const void Matrix4D::move (const Vector3f& rclVct) { - dMtrx4D[0][3] += rclVct.x; - dMtrx4D[1][3] += rclVct.y; - dMtrx4D[2][3] += rclVct.z; + move(convertTo(rclVct)); } void Matrix4D::move (const Vector3d& rclVct) @@ -128,12 +139,7 @@ void Matrix4D::move (const Vector3d& rclVct) void Matrix4D::scale (const Vector3f& rclVct) { - Matrix4D clMat; - - clMat.dMtrx4D[0][0] = rclVct.x; - clMat.dMtrx4D[1][1] = rclVct.y; - clMat.dMtrx4D[2][2] = rclVct.z; - (*this) = clMat * (*this); + scale(convertTo(rclVct)); } void Matrix4D::scale (const Vector3d& rclVct) @@ -242,8 +248,8 @@ void Matrix4D::rotLine(const Vector3d& rclVct, double fAngle) void Matrix4D::rotLine(const Vector3f& rclVct, float fAngle) { - Vector3d tmp(rclVct.x,rclVct.y,rclVct.z); - rotLine(tmp,fAngle); + Vector3d tmp = convertTo(rclVct); + rotLine(tmp, static_cast(fAngle)); } void Matrix4D::rotLine(const Vector3d& rclBase, const Vector3d& rclDir, double fAngle) @@ -255,9 +261,9 @@ void Matrix4D::rotLine(const Vector3d& rclBase, const Vector3d& rclDir, double f void Matrix4D::rotLine(const Vector3f& rclBase, const Vector3f& rclDir, float fAngle) { - Vector3d pnt(rclBase.x,rclBase.y,rclBase.z); - Vector3d dir(rclDir.x,rclDir.y,rclDir.z); - rotLine(pnt,dir,fAngle); + Vector3d pnt = convertTo(rclBase); + Vector3d dir = convertTo(rclDir); + rotLine(pnt,dir,static_cast(fAngle)); } /** @@ -273,129 +279,20 @@ void Matrix4D::rotLine(const Vector3f& rclBase, const Vector3f& rclDir, float fA */ bool Matrix4D::toAxisAngle (Vector3f& rclBase, Vector3f& rclDir, float& rfAngle, float& fTranslation) const { - // First check if the 3x3 submatrix is orthogonal - for ( int i=0; i<3; i++ ) { - // length must be one - if ( fabs(dMtrx4D[0][i]*dMtrx4D[0][i]+dMtrx4D[1][i]*dMtrx4D[1][i]+dMtrx4D[2][i]*dMtrx4D[2][i]-1.0) > 0.01 ) - return false; - // scalar product with other rows must be zero - if ( fabs(dMtrx4D[0][i]*dMtrx4D[0][(i+1)%3]+dMtrx4D[1][i]*dMtrx4D[1][(i+1)%3]+dMtrx4D[2][i]*dMtrx4D[2][(i+1)%3]) > 0.01 ) - return false; - } + Vector3d pnt = convertTo(rclBase); + Vector3d dir = convertTo(rclDir); + double dAngle = static_cast(rfAngle); + double dTranslation = static_cast(fTranslation); - // Okay, the 3x3 matrix is orthogonal. - // Note: The section to get the rotation axis and angle was taken from WildMagic Library. - // - // Let (x,y,z) be the unit-length axis and let A be an angle of rotation. - // The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where - // I is the identity and - // - // +- -+ - // P = | 0 -z +y | - // | +z 0 -x | - // | -y +x 0 | - // +- -+ - // - // If A > 0, R represents a counterclockwise rotation about the axis in - // the sense of looking from the tip of the axis vector towards the - // origin. Some algebra will show that - // - // cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P - // - // In the event that A = pi, R-R^t = 0 which prevents us from extracting - // the axis through P. Instead note that R = I+2*P^2 when A = pi, so - // P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and - // z^2-1. We can solve these for axis (x,y,z). Because the angle is pi, - // it does not matter which sign you choose on the square roots. - // - // For more details see also http://www.math.niu.edu/~rusin/known-math/97/rotations - - double fTrace = dMtrx4D[0][0] + dMtrx4D[1][1] + dMtrx4D[2][2]; - double fCos = 0.5*(fTrace-1.0); - rfAngle = (float)acos(fCos); // in [0,PI] - - if ( rfAngle > 0.0f ) - { - if ( rfAngle < F_PI ) - { - rclDir.x = (float)(dMtrx4D[2][1]-dMtrx4D[1][2]); - rclDir.y = (float)(dMtrx4D[0][2]-dMtrx4D[2][0]); - rclDir.z = (float)(dMtrx4D[1][0]-dMtrx4D[0][1]); - rclDir.Normalize(); + bool ok = toAxisAngle(pnt, dir, dAngle, dTranslation); + if (ok) { + rclBase = convertTo(pnt); + rclDir = convertTo(dir); + rfAngle = static_cast(dAngle); + fTranslation = static_cast(dTranslation); } - else - { - // angle is PI - double fHalfInverse; - if ( dMtrx4D[0][0] >= dMtrx4D[1][1] ) - { - // r00 >= r11 - if ( dMtrx4D[0][0] >= dMtrx4D[2][2] ) - { - // r00 is maximum diagonal term - rclDir.x = (float)(0.5*sqrt(dMtrx4D[0][0] - dMtrx4D[1][1] - dMtrx4D[2][2] + 1.0)); - fHalfInverse = 0.5/rclDir.x; - rclDir.y = (float)(fHalfInverse*dMtrx4D[0][1]); - rclDir.z = (float)(fHalfInverse*dMtrx4D[0][2]); - } - else - { - // r22 is maximum diagonal term - rclDir.z = (float)(0.5*sqrt(dMtrx4D[2][2] - dMtrx4D[0][0] - dMtrx4D[1][1] + 1.0)); - fHalfInverse = 0.5/rclDir.z; - rclDir.x = (float)(fHalfInverse*dMtrx4D[0][2]); - rclDir.y = (float)(fHalfInverse*dMtrx4D[1][2]); - } - } - else - { - // r11 > r00 - if ( dMtrx4D[1][1] >= dMtrx4D[2][2] ) - { - // r11 is maximum diagonal term - rclDir.y = (float)(0.5*sqrt(dMtrx4D[1][1] - dMtrx4D[0][0] - dMtrx4D[2][2] + 1.0)); - fHalfInverse = 0.5/rclDir.y; - rclDir.x = (float)(fHalfInverse*dMtrx4D[0][1]); - rclDir.z = (float)(fHalfInverse*dMtrx4D[1][2]); - } - else - { - // r22 is maximum diagonal term - rclDir.z = (float)(0.5*sqrt(dMtrx4D[2][2] - dMtrx4D[0][0] - dMtrx4D[1][1] + 1.0)); - fHalfInverse = 0.5/rclDir.z; - rclDir.x = (float)(fHalfInverse*dMtrx4D[0][2]); - rclDir.y = (float)(fHalfInverse*dMtrx4D[1][2]); - } - } - } - } - else - { - // The angle is 0 and the matrix is the identity. Any axis will - // work, so just use the x-axis. - rclDir.x = 1.0f; - rclDir.y = 0.0f; - rclDir.z = 0.0f; - rclBase.x = 0.0f; - rclBase.y = 0.0f; - rclBase.z = 0.0f; - } - // This is the translation part in axis direction - fTranslation = (float)(dMtrx4D[0][3]*rclDir.x+dMtrx4D[1][3]*rclDir.y+dMtrx4D[2][3]*rclDir.z); - Vector3f cPnt((float)dMtrx4D[0][3],(float)dMtrx4D[1][3],(float)dMtrx4D[2][3]); - cPnt = cPnt - fTranslation * rclDir; - - // This is the base point of the rotation axis - if ( rfAngle > 0.0f ) - { - double factor = 0.5*(1.0+fTrace)/sin(rfAngle); - rclBase.x = (float)(0.5*(cPnt.x+factor*(rclDir.y*cPnt.z-rclDir.z*cPnt.y))); - rclBase.y = (float)(0.5*(cPnt.y+factor*(rclDir.z*cPnt.x-rclDir.x*cPnt.z))); - rclBase.z = (float)(0.5*(cPnt.z+factor*(rclDir.x*cPnt.y-rclDir.y*cPnt.x))); - } - - return true; + return ok; } bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle, double& fTranslation) const @@ -441,9 +338,9 @@ bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle double fCos = 0.5*(fTrace-1.0); rfAngle = acos(fCos); // in [0,PI] - if ( rfAngle > 0.0f ) + if ( rfAngle > 0.0 ) { - if ( rfAngle < F_PI ) + if ( rfAngle < D_PI ) { rclDir.x = (dMtrx4D[2][1]-dMtrx4D[1][2]); rclDir.y = (dMtrx4D[0][2]-dMtrx4D[2][0]); @@ -514,7 +411,7 @@ bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle cPnt = cPnt - fTranslation * rclDir; // This is the base point of the rotation axis - if ( rfAngle > 0.0f ) + if ( rfAngle > 0.0 ) { double factor = 0.5*(1.0+fTrace)/sin(rfAngle); rclBase.x = (0.5*(cPnt.x+factor*(rclDir.y*cPnt.z-rclDir.z*cPnt.y))); @@ -601,7 +498,7 @@ void Matrix_gauss(Matrix a, Matrix b) } indxr[i] = irow; indxc[i] = icol; - if (a[4*icol+icol] == 0) return; + if (a[4*icol+icol] == 0.0) return; pivinv = 1.0/a[4*icol+icol]; a[4*icol+icol] = 1.0; for (l = 0; l < 4; l++) @@ -820,8 +717,8 @@ std::string Matrix4D::analyse(void) const trp.transpose(); trp = trp * sub; bool ortho = true; - for (int i=0; i<4 && ortho; i++) { - for (int j=0; j<4 && ortho; j++) { + for (unsigned short i=0; i<4 && ortho; i++) { + for (unsigned short j=0; j<4 && ortho; j++) { if (i != j) { if (fabs(trp[i][j]) > eps) { ortho = false; @@ -876,17 +773,7 @@ Matrix4D& Matrix4D::Outer(const Vector3f& rV1, const Vector3f& rV2) { setToUnity(); - dMtrx4D[0][0] = rV1.x * rV2.x; - dMtrx4D[0][1] = rV1.x * rV2.y; - dMtrx4D[0][2] = rV1.x * rV2.z; - - dMtrx4D[1][0] = rV1.y * rV2.x; - dMtrx4D[1][1] = rV1.y * rV2.y; - dMtrx4D[1][2] = rV1.y * rV2.z; - - dMtrx4D[2][0] = rV1.z * rV2.x; - dMtrx4D[2][1] = rV1.z * rV2.y; - dMtrx4D[2][2] = rV1.z * rV2.z; + Outer(convertTo(rV1), convertTo(rV2)); return *this; } @@ -914,17 +801,7 @@ Matrix4D& Matrix4D::Hat(const Vector3f& rV) { setToUnity(); - dMtrx4D[0][0] = 0.0; - dMtrx4D[0][1] = -rV.z; - dMtrx4D[0][2] = rV.y; - - dMtrx4D[1][0] = rV.z; - dMtrx4D[1][1] = 0.0; - dMtrx4D[1][2] = -rV.x; - - dMtrx4D[2][0] = -rV.y; - dMtrx4D[2][1] = rV.x; - dMtrx4D[2][2] = 0.0; + Hat(convertTo(rV)); return *this; } @@ -948,24 +825,27 @@ Matrix4D& Matrix4D::Hat(const Vector3d& rV) return *this; } -int Matrix4D::hasScale(double tol) const { +int Matrix4D::hasScale(double tol) const +{ // check for uniform scaling // // scaling factors are the column vector length. We use square distance and // ignore the actual scaling signess // - if(tol == 0.0) + if (tol == 0.0) tol = 1e-9; double dx = Vector3d(dMtrx4D[0][0],dMtrx4D[1][0],dMtrx4D[2][0]).Sqr(); double dy = Vector3d(dMtrx4D[0][1],dMtrx4D[1][1],dMtrx4D[2][1]).Sqr(); - if(fabs(dx-dy)>tol) + if (fabs(dx-dy) > tol) { return -1; + } else { double dz = Vector3d(dMtrx4D[0][2],dMtrx4D[1][2],dMtrx4D[2][2]).Sqr(); - if(fabs(dy-dz)>tol) + if (fabs(dy-dz) > tol) return -1; } - if(fabs(dx-1.0)>tol) + + if (fabs(dx-1.0) > tol) return 1; else return 0; diff --git a/src/Base/Matrix.h b/src/Base/Matrix.h index d806b1a3dd..3002cd03f9 100644 --- a/src/Base/Matrix.h +++ b/src/Base/Matrix.h @@ -180,7 +180,7 @@ private: inline Matrix4D Matrix4D::operator + (const Matrix4D& rclMtrx) const { Matrix4D clMat; - short iz, is; + unsigned short iz, is; for (iz = 0; iz < 4; iz++) { for (is = 0; is < 4; is++) { @@ -193,7 +193,7 @@ inline Matrix4D Matrix4D::operator + (const Matrix4D& rclMtrx) const inline Matrix4D& Matrix4D::operator += (const Matrix4D& rclMtrx) { - short iz, is; + unsigned short iz, is; for (iz = 0; iz < 4; iz++) { for (is = 0; is < 4; is++) { @@ -207,7 +207,7 @@ inline Matrix4D& Matrix4D::operator += (const Matrix4D& rclMtrx) inline Matrix4D Matrix4D::operator - (const Matrix4D& rclMtrx) const { Matrix4D clMat; - short iz, is; + unsigned short iz, is; for (iz = 0; iz < 4; iz++) { for (is = 0; is < 4; is++) { @@ -220,7 +220,7 @@ inline Matrix4D Matrix4D::operator - (const Matrix4D& rclMtrx) const inline Matrix4D& Matrix4D::operator -= (const Matrix4D& rclMtrx) { - short iz, is; + unsigned short iz, is; for (iz = 0; iz < 4; iz++) { for (is = 0; is < 4; is++) { @@ -234,7 +234,7 @@ inline Matrix4D& Matrix4D::operator -= (const Matrix4D& rclMtrx) inline Matrix4D& Matrix4D::operator *= (const Matrix4D& rclMtrx) { Matrix4D clMat; - short ie, iz, is; + unsigned short ie, iz, is; for (iz = 0; iz < 4; iz++) for (is = 0; is < 4; is++) { @@ -252,7 +252,7 @@ inline Matrix4D& Matrix4D::operator *= (const Matrix4D& rclMtrx) inline Matrix4D Matrix4D::operator * (const Matrix4D& rclMtrx) const { Matrix4D clMat; - short ie, iz, is; + unsigned short ie, iz, is; for (iz = 0; iz < 4; iz++) for (is = 0; is < 4; is++) { @@ -267,7 +267,7 @@ inline Matrix4D Matrix4D::operator * (const Matrix4D& rclMtrx) const inline Matrix4D& Matrix4D::operator= (const Matrix4D& rclMtrx) { - short iz, is; + unsigned short iz, is; for (iz = 0; iz < 4; iz++) { for (is = 0; is < 4; is++) { @@ -280,12 +280,17 @@ inline Matrix4D& Matrix4D::operator= (const Matrix4D& rclMtrx) inline Vector3f Matrix4D::operator* (const Vector3f& rclVct) const { - return Vector3f((float)(dMtrx4D[0][0]*rclVct.x + dMtrx4D[0][1]*rclVct.y + - dMtrx4D[0][2]*rclVct.z + dMtrx4D[0][3]), - (float)(dMtrx4D[1][0]*rclVct.x + dMtrx4D[1][1]*rclVct.y + - dMtrx4D[1][2]*rclVct.z + dMtrx4D[1][3]), - (float)(dMtrx4D[2][0]*rclVct.x + dMtrx4D[2][1]*rclVct.y + - dMtrx4D[2][2]*rclVct.z + dMtrx4D[2][3])); + double x = static_cast(rclVct.x); + double y = static_cast(rclVct.y); + double z = static_cast(rclVct.z); + return Vector3f( + static_cast(dMtrx4D[0][0]*x + dMtrx4D[0][1]*y + + dMtrx4D[0][2]*z + dMtrx4D[0][3]), + static_cast(dMtrx4D[1][0]*x + dMtrx4D[1][1]*y + + dMtrx4D[1][2]*z + dMtrx4D[1][3]), + static_cast(dMtrx4D[2][0]*x + dMtrx4D[2][1]*y + + dMtrx4D[2][2]*z + dMtrx4D[2][3]) + ); } inline Vector3d Matrix4D::operator* (const Vector3d& rclVct) const @@ -311,12 +316,16 @@ inline void Matrix4D::multVec(const Vector3d & src, Vector3d & dst) const inline void Matrix4D::multVec(const Vector3f & src, Vector3f & dst) const { - double x = (dMtrx4D[0][0]*src.x + dMtrx4D[0][1]*src.y + - dMtrx4D[0][2]*src.z + dMtrx4D[0][3]); - double y = (dMtrx4D[1][0]*src.x + dMtrx4D[1][1]*src.y + - dMtrx4D[1][2]*src.z + dMtrx4D[1][3]); - double z = (dMtrx4D[2][0]*src.x + dMtrx4D[2][1]*src.y + - dMtrx4D[2][2]*src.z + dMtrx4D[2][3]); + double sx = static_cast(src.x); + double sy = static_cast(src.y); + double sz = static_cast(src.z); + + double x = (dMtrx4D[0][0]*sx + dMtrx4D[0][1]*sy + + dMtrx4D[0][2]*sz + dMtrx4D[0][3]); + double y = (dMtrx4D[1][0]*sx + dMtrx4D[1][1]*sy + + dMtrx4D[1][2]*sz + dMtrx4D[1][3]); + double z = (dMtrx4D[2][0]*sx + dMtrx4D[2][1]*sy + + dMtrx4D[2][2]*sz + dMtrx4D[2][3]); dst.Set(static_cast(x), static_cast(y), static_cast(z)); @@ -324,12 +333,14 @@ inline void Matrix4D::multVec(const Vector3f & src, Vector3f & dst) const inline bool Matrix4D::operator== (const Matrix4D& rclMtrx) const { - short iz, is; + unsigned short iz, is; - for (iz = 0; iz < 4; iz++) - for (is = 0; is < 4; is++) + for (iz = 0; iz < 4; iz++) { + for (is = 0; is < 4; is++) { if (fabs(dMtrx4D[iz][is] - rclMtrx.dMtrx4D[iz][is]) > traits_type::epsilon()) return false; + } + } return true; } diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index 9cf9815f0a..24bb6840b7 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -122,8 +122,8 @@ void Rotation::evaluateVector() // // Note: -1 < w < +1 (|w| == 1 not allowed, with w:=quat[3]) if((this->quat[3] > -1.0) && (this->quat[3] < 1.0)) { - double rfAngle = double(acos(this->quat[3])) * 2.0; - double scale = (double)sin(rfAngle / 2.0); + double rfAngle = acos(this->quat[3]) * 2.0; + double scale = sin(rfAngle / 2.0); // Get a normalized vector double l = this->_axis.Length(); if (l < Base::Vector3d::epsilon()) l = 1; @@ -211,32 +211,32 @@ void Rotation::setValue(const double q[4]) void Rotation::setValue(const Matrix4D & m) { - double trace = (double)(m[0][0] + m[1][1] + m[2][2]); + double trace = (m[0][0] + m[1][1] + m[2][2]); if (trace > 0.0) { double s = sqrt(1.0+trace); this->quat[3] = 0.5 * s; s = 0.5 / s; - this->quat[0] = (double)((m[2][1] - m[1][2]) * s); - this->quat[1] = (double)((m[0][2] - m[2][0]) * s); - this->quat[2] = (double)((m[1][0] - m[0][1]) * s); + this->quat[0] = ((m[2][1] - m[1][2]) * s); + this->quat[1] = ((m[0][2] - m[2][0]) * s); + this->quat[2] = ((m[1][0] - m[0][1]) * s); } else { // Described in RotationIssues.pdf from // // Get the max. element of the trace - int i = 0; + unsigned short i = 0; if (m[1][1] > m[0][0]) i = 1; if (m[2][2] > m[i][i]) i = 2; - int j = (i+1)%3; - int k = (i+2)%3; + unsigned short j = (i+1)%3; + unsigned short k = (i+2)%3; - double s = (double)sqrt((m[i][i] - (m[j][j] + m[k][k])) + 1.0); + double s = sqrt((m[i][i] - (m[j][j] + m[k][k])) + 1.0); this->quat[i] = s * 0.5; s = 0.5 / s; - this->quat[3] = (double)((m[k][j] - m[j][k]) * s); - this->quat[j] = (double)((m[j][i] + m[i][j]) * s); - this->quat[k] = (double)((m[k][i] + m[i][k]) * s); + this->quat[3] = ((m[k][j] - m[j][k]) * s); + this->quat[j] = ((m[j][i] + m[i][j]) * s); + this->quat[k] = ((m[k][i] + m[i][k]) * s); } this->evaluateVector(); @@ -249,7 +249,7 @@ void Rotation::setValue(const Vector3d & axis, const double fAngle) // normalization of the angle to be in [0, 2pi[ _angle = fAngle; double theAngle = fAngle - floor(fAngle / (2.0 * D_PI))*(2.0 * D_PI); - this->quat[3] = (double)cos(theAngle/2.0); + this->quat[3] = cos(theAngle/2.0); Vector3d norm = axis; norm.Normalize(); @@ -263,7 +263,7 @@ void Rotation::setValue(const Vector3d & axis, const double fAngle) norm.Normalize(); } - double scale = (double)sin(theAngle/2.0); + double scale = sin(theAngle/2.0); this->quat[0] = norm.x * scale; this->quat[1] = norm.y * scale; this->quat[2] = norm.z * scale; @@ -295,18 +295,18 @@ void Rotation::setValue(const Vector3d & rotateFrom, const Vector3d & rotateTo) else { // Vectors are not parallel // Note: A quaternion is not well-defined by specifying a point and its transformed point. // Every quaternion with a rotation axis having the same angle to the vectors of both points is okay. - double angle = (double)acos(dot); + double angle = acos(dot); this->setValue(w, angle); } } void Rotation::normalize() { - double len = (double)sqrt(this->quat[0]*this->quat[0]+ - this->quat[1]*this->quat[1]+ - this->quat[2]*this->quat[2]+ - this->quat[3]*this->quat[3]); - if (len != 0) { + double len = sqrt(this->quat[0]*this->quat[0]+ + this->quat[1]*this->quat[1]+ + this->quat[2]*this->quat[2]+ + this->quat[3]*this->quat[3]); + if (len > 0.0) { this->quat[0] /= len; this->quat[1] /= len; this->quat[2] /= len; @@ -461,8 +461,8 @@ Rotation Rotation::slerp(const Rotation & q0, const Rotation & q1, double t) } if ((1.0 - dot) > Base::Vector3d::epsilon()) { - double angle = (double)acos(dot); - double sinangle = (double)sin(angle); + double angle = acos(dot); + double sinangle = sin(angle); // If possible calculate spherical interpolation, otherwise use linear interpolation if (sinangle > Base::Vector3d::epsilon()) { scale0 = double(sin((1.0 - t) * angle)) / sinangle; @@ -553,7 +553,7 @@ Rotation Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdi if (i == 1) hintDir = Vector3d(); //no vector can be used as hint direction. Zero it out, to indicate that a guess is needed. } - if (hintDir.Length() == 0){ + if (hintDir.Length() == 0.0){ switch (order[0]){ case X: { //xdir is main //align zdir to OZ @@ -698,17 +698,17 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const bool Rotation::isIdentity() const { - return ((this->quat[0] == 0 && - this->quat[1] == 0 && - this->quat[2] == 0) && - (this->quat[3] == 1 || - this->quat[3] == -1)); + return ((this->quat[0] == 0.0 && + this->quat[1] == 0.0 && + this->quat[2] == 0.0) && + (this->quat[3] == 1.0 || + this->quat[3] == -1.0)); } bool Rotation::isNull() const { - return (this->quat[0] == 0 && - this->quat[1] == 0 && - this->quat[2] == 0 && - this->quat[3] == 0); + return (this->quat[0] == 0.0 && + this->quat[1] == 0.0 && + this->quat[2] == 0.0 && + this->quat[3] == 0.0); } diff --git a/src/Base/Vector3D.h b/src/Base/Vector3D.h index 5363428b4b..4b0f4a414d 100644 --- a/src/Base/Vector3D.h +++ b/src/Base/Vector3D.h @@ -90,7 +90,7 @@ public: //@} /// Construction - explicit Vector3 (_Precision fx = 0.0f, _Precision fy = 0.0f, _Precision fz = 0.0f); + explicit Vector3 (_Precision fx = 0.0, _Precision fy = 0.0, _Precision fz = 0.0); /// Construction Vector3 (const Vector3<_Precision>& rcVct); @@ -217,7 +217,7 @@ template inline _Precision Distance (const Vector3<_Precision> &v1, const Vector3<_Precision> &v2) { _Precision x=v1.x-v2.x, y=v1.y-v2.y, z=v1.z-v2.z; - return (_Precision)sqrt((x * x) + (y * y) + (z * z)); + return static_cast<_Precision>(sqrt((x * x) + (y * y) + (z * z))); } /// Returns the squared distance between two points @@ -238,7 +238,7 @@ inline Vector3<_Precision> operator * (_Precision fFac, const Vector3<_Precision template inline Vector3<_Pr1> toVector(const Vector3<_Pr2>& v) { - return Vector3<_Pr1>((_Pr1)v.x,(_Pr1)v.y,(_Pr1)v.z); + return Vector3<_Pr1>(static_cast<_Pr1>(v.x),static_cast<_Pr1>(v.y),static_cast<_Pr1>(v.z)); } typedef Vector3 Vector3f; diff --git a/src/Base/XMLTools.h b/src/Base/XMLTools.h index e96e9c6707..b735d9a0ce 100644 --- a/src/Base/XMLTools.h +++ b/src/Base/XMLTools.h @@ -154,7 +154,7 @@ inline StrXUTF8::StrXUTF8(const XMLCh* const toTranscode) while (inputLength) { outputLength = transcoder->transcodeTo(toTranscode + offset, inputLength, outBuff, 128, eaten, XMLTranscoder::UnRep_RepChar); - str.append((const char*)outBuff, outputLength); + str.append(reinterpret_cast(outBuff), outputLength); offset += eaten; inputLength -= eaten; @@ -258,7 +258,7 @@ inline XUTF8Str::XUTF8Str(const char* const fromTranscode) } static XMLCh outBuff[128]; - XMLByte* xmlBytes = (XMLByte*)fromTranscode; + const XMLByte* xmlBytes = reinterpret_cast(fromTranscode); #if (XERCES_VERSION_MAJOR == 2) unsigned int outputLength; unsigned int eaten = 0;