[TechDraw] Use templates instead of duplicate code: formatVector

This commit is contained in:
Benjamin Bræstrup Sayoc
2024-10-08 00:42:57 +02:00
parent 1d7e7c86a0
commit 7bc9304a21
2 changed files with 19 additions and 54 deletions

View File

@@ -485,7 +485,8 @@ Base::Vector3d DrawUtil::vertex2Vector(const TopoDS_Vertex& v)
return Base::Vector3d(gp.X(), gp.Y(), gp.Z());
}
//TODO: make formatVector using toVector3d
// template specialization
//template <> // GCC BUG 85282, wanting this to be outside class body
std::string DrawUtil::formatVector(const Base::Vector3d& v)
{
std::stringstream builder;
@@ -493,51 +494,7 @@ std::string DrawUtil::formatVector(const Base::Vector3d& v)
builder << " (" << v.x << ", " << v.y << ", " << v.z << ") ";
return builder.str();
}
template <> // GCC BUG 85282, wanting this to be outside class body
Base::Vector3d DrawUtil::toVector3d<QPointF>(const QPointF& v)
{
return Base::Vector3d(v.x(), v.y(), 0);
}
std::string DrawUtil::formatVector(const gp_Dir2d& v)
{
std::stringstream builder;
builder << std::fixed << std::setprecision(Base::UnitsApi::getDecimals());
builder << " (" << v.X() << ", " << v.Y() << ") ";
return builder.str();
}
std::string DrawUtil::formatVector(const gp_Vec& v)
{
std::stringstream builder;
builder << std::fixed << std::setprecision(Base::UnitsApi::getDecimals());
builder << " (" << v.X() << ", " << v.Y() << ", " << v.Z() << ") ";
return builder.str();
}
std::string DrawUtil::formatVector(const gp_Pnt& v)
{
std::stringstream builder;
builder << std::fixed << std::setprecision(Base::UnitsApi::getDecimals());
builder << " (" << v.X() << ", " << v.Y() << ", " << v.Z() << ") ";
return builder.str();
}
std::string DrawUtil::formatVector(const gp_Pnt2d& v)
{
std::stringstream builder;
builder << std::fixed << std::setprecision(Base::UnitsApi::getDecimals());
builder << " (" << v.X() << ", " << v.Y() << ") ";
return builder.str();
}
std::string DrawUtil::formatVector(const QPointF& v)
{
std::stringstream builder;
builder << std::fixed << std::setprecision(Base::UnitsApi::getDecimals());
builder << " (" << v.x() << ", " << v.y() << ") ";
return builder.str();
}
//template std::string DrawUtil::formatVector<Base::Vector3d>(const Base::Vector3d &v);
//! compare 2 vectors for sorting - true if v1 < v2
//! precision::Confusion() is too strict for vertex - vertex comparisons

View File

@@ -116,13 +116,12 @@ public:
static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v);
template <typename T>
static std::string formatVector(const T& v)
{
return formatVector(toVector3d(v));
}
static std::string formatVector(const Base::Vector3d& v);
static std::string formatVector(const gp_Dir& v);
static std::string formatVector(const gp_Dir2d& v);
static std::string formatVector(const gp_Vec& v);
static std::string formatVector(const gp_Pnt& v);
static std::string formatVector(const gp_Pnt2d& v);
static std::string formatVector(const QPointF& v);
static bool vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2);
//!std::map require comparator to be a type not a function
@@ -176,6 +175,11 @@ public:
return Base::Vector3d(v.X(), v.Y(), v.Z());
}
static Base::Vector3d toVector3d(const QPointF& v)
{
return Base::Vector3d(v.x(), v.y(), 0);
}
//! To gp_*
// TODO: Would this be relevant to move to Base::Vector3d? Probably
template <typename T>
@@ -280,8 +284,12 @@ public:
static void dumpEdges(const char* text, const TopoDS_Shape& s);
};
template <> // GCC BUG 85282, wanting this to be outside class body. This is only the declaration, the definition .cpp
Base::Vector3d DrawUtil::toVector3d<QPointF>(const QPointF& v);
// GCC BUG 85282, wanting this to be outside class body. This is only the declaration, the definition .cpp
//template<> std::string DrawUtil::formatVector<Base::Vector3d>(const Base::Vector3d &v);
// GCC BUG 85282, wanting this to be outside class body. This is only the declaration, the definition .cpp
//template<> Base::Vector3d DrawUtil::toVector3d<QPointF>(const QPointF& v);
}//end namespace TechDraw
#endif