[TD]fix direction precision error #9572

This commit is contained in:
wandererfan
2023-05-15 08:53:52 -04:00
committed by WandererFan
parent 01da66f2df
commit 8eeb095fcc
2 changed files with 32 additions and 5 deletions

View File

@@ -383,14 +383,29 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
return std::make_pair(viewDir, viewRight);
}
// Coin is giving us a values like 0.000000134439 instead of 0.000000000000.
// This small difference caused circles to be projected as ellipses among other
// problems.
// Since SbVec3f is single precision floating point, it is only good to 6-9
// significant decimal digits, and the rest of TechDraw works with doubles
// that are good to 15-18 significant decimal digits.
// But. When a float is promoted to double the value is supposed to be unchanged!
// So where do the garbage digits come from???
// In any case, if we restrict directions to 6 digits, we avoid the problem.
int digits(6);
SbVec3f dvec = viewer->getViewDirection();
SbVec3f upvec = viewer->getUpDirection();
viewDir = Base::Vector3d(dvec[0], dvec[1], dvec[2]);
double dvecX = roundToDigits(dvec[0], digits);
double dvecY = roundToDigits(dvec[1], digits);
double dvecZ = roundToDigits(dvec[2], digits);
viewDir = Base::Vector3d(dvecX, dvecY, dvecZ);
viewDir = viewDir * (-1.0);// Inventor dir is opposite TD projection dir
viewUp = Base::Vector3d(upvec[0], upvec[1], upvec[2]);
// Base::Vector3d dirXup = viewDir.Cross(viewUp);
SbVec3f upvec = viewer->getUpDirection();
double upvecX = roundToDigits(upvec[0], digits);
double upvecY = roundToDigits(upvec[1], digits);
double upvecZ = roundToDigits(upvec[2], digits);
viewUp = Base::Vector3d(upvecX, upvecY, upvecZ);
Base::Vector3d right = viewUp.Cross(viewDir);
result = std::make_pair(viewDir, right);
@@ -436,3 +451,13 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawGuiUtil::getProjDirFromFace(App::D
return std::make_pair(projDir, rotVec);
}
// converts original value to one with only digits significant figures
double DrawGuiUtil::roundToDigits(double original, int digits)
{
double factor = std::pow(10.0, digits);
double temp = original * factor;
double rounded = std::round(temp);
temp = rounded / factor;
return temp;
}

View File

@@ -71,6 +71,8 @@ class TechDrawGuiExport DrawGuiUtil {
std::string faceName);
static void loadArrowBox(QComboBox* qcb);
static double roundToDigits(double original, int digits);
};