diff --git a/src/Mod/TechDraw/App/DrawProjectSplit.cpp b/src/Mod/TechDraw/App/DrawProjectSplit.cpp index c1671cea7..f5276b2cf 100644 --- a/src/Mod/TechDraw/App/DrawProjectSplit.cpp +++ b/src/Mod/TechDraw/App/DrawProjectSplit.cpp @@ -421,7 +421,7 @@ std::vector DrawProjectSplit::removeDuplicateEdges(std::vector 0) { + if (DrawUtil::vectorLess(item.end,item.start)) { Base::Vector3d vTemp = item.start; item.start = item.end; item.end = vTemp; @@ -453,7 +453,7 @@ std::vector DrawProjectSplit::removeDuplicateEdges(std::vector DrawProjectSplit::sortEdges(std::vector& e, bool ascend) { std::vector sorted = e; - std::sort(sorted.begin(), sorted.end(), edgeSortItem::edgeCompare); + std::sort(sorted.begin(), sorted.end(), edgeSortItem::edgeLess); if (ascend) { std::reverse(sorted.begin(),sorted.end()); } @@ -476,24 +476,23 @@ std::string edgeSortItem::dump(void) //true if "e1 < e2" - for sorting -/*static*/bool edgeSortItem::edgeCompare(const edgeSortItem& e1, const edgeSortItem& e2) +/*static*/bool edgeSortItem::edgeLess(const edgeSortItem& e1, const edgeSortItem& e2) { bool result = false; - int vCompare = DrawUtil::vectorCompare(e1.start, e2.start); - if ( vCompare == -1) { - result = true; - } else if (vCompare == 0) { - if (e1.startAngle < e2.startAngle) { - result = true; - } else if (DrawUtil::fpCompare(e1.startAngle, e2.startAngle)) { - if (e1.endAngle < e2.startAngle) { - result = true; - } else if (DrawUtil::fpCompare(e1.endAngle, e2.endAngle)) { - if (e1.idx < e2.idx) { - result = true; - } - } + if (e1.start != e2.start) { + if ( DrawUtil::vectorLess(e1.start, e2.start)) { + result = true; } + } else if (!DrawUtil::fpCompare(e1.startAngle, e2.startAngle)) { + if (e1.startAngle < e2.startAngle) { + result = true; + } + } else if (!DrawUtil::fpCompare(e1.endAngle, e2.endAngle)) { + if (e1.endAngle < e2.startAngle) { + result = true; + } + } else if (e1.idx < e2.idx) { + result = true; } return result; } diff --git a/src/Mod/TechDraw/App/DrawProjectSplit.h b/src/Mod/TechDraw/App/DrawProjectSplit.h index 24822c789..75388711f 100644 --- a/src/Mod/TechDraw/App/DrawProjectSplit.h +++ b/src/Mod/TechDraw/App/DrawProjectSplit.h @@ -68,7 +68,7 @@ public: double endAngle; unsigned int idx; - static bool edgeCompare(const edgeSortItem& e1, const edgeSortItem& e2); + static bool edgeLess(const edgeSortItem& e1, const edgeSortItem& e2); static bool edgeEqual(const edgeSortItem& e1, const edgeSortItem& e2); std::string dump(void); }; diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index db00a2154..f8a3e8952 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -277,33 +277,22 @@ std::string DrawUtil::formatVector(const Base::Vector3d& v) return result; } -//! compare 2 vectors for sorting purposes ( -1 -> v1 v1 == v2, 1 -> v1 > v2) -int DrawUtil::vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2) +//! compare 2 vectors for sorting - true if v1 < v2 +bool DrawUtil::vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2) { - int result = 0; - if (v1 == v2) { - return result; - } - - if (v1.x < v2.x) { - result = -1; - } else if (DrawUtil::fpCompare(v1.x, v2.x)) { - if (v1.y < v2.y) { - result = -1; - } else if (DrawUtil::fpCompare(v1.y, v2.y)) { - if (v1.z < v2.z) { - result = -1; - } else { - result = 1; - } + bool result = false; + if (v1 != v2) { + if (!DrawUtil::fpCompare(v1.x,v2.x)) { + result = v1.x < v2.x; + } else if (!DrawUtil::fpCompare(v1.y,v2.y)) { + result = v1.y < v2.y; } else { - result = 1; //v2y > v1y + result = v1.z < v2.z; } - } else { - result = 1; //v1x > v2x } return result; -} +} + //!convert fromPoint in coordinate system fromSystem to reference coordinate system Base::Vector3d DrawUtil::toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint) diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 739a2e284..41059cfdb 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -59,7 +59,7 @@ class TechDrawExport DrawUtil { static bool fpCompare(const double& d1, const double& d2); static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v); static std::string formatVector(const Base::Vector3d& v); - static int vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2); + static bool vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2); static Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint); static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2); //! rotate vector by angle radians around axis through org