From c46a4f776bd975b149bf6b296cf383de2d55fd8e Mon Sep 17 00:00:00 2001 From: edi271 Date: Tue, 18 Jan 2022 17:06:39 +0100 Subject: [PATCH] [TD] Move Circulation method to DrawUtil --- src/Mod/TechDraw/App/Cosmetic.cpp | 20 +------------------ src/Mod/TechDraw/App/Cosmetic.h | 1 - src/Mod/TechDraw/App/DrawUtil.cpp | 9 +++++++++ src/Mod/TechDraw/App/DrawUtil.h | 1 + src/Mod/TechDraw/Gui/CommandExtensionPack.cpp | 11 +--------- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 1d9885f12b..dec8b5c034 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -976,24 +976,6 @@ std::pair CenterLine::calcEndPoints(DrawViewPart return result; } -bool CenterLine::Circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C) -{ - // the determinant of this matrix calculates the area of a triangle, see - // https://en.wikipedia.org/wiki/Triangle#Using_coordinates - // a 3x3 matrix would also do the job, but FC supports only 4x4 matrixes - Base::Matrix4D CircMatrix( - A.x, A.y, 1, 0, - B.x, B.y, 1, 0, - C.x, C.y, 1, 0, - 0, 0, 0, 1); - - // the sign delivers the dicrection of travel along the triangle edges - if (CircMatrix.determinant() > 0) - return true; - else - return false; -} - std::pair CenterLine::calcEndPoints2Lines(DrawViewPart* partFeat, std::vector edgeNames, int mode, double ext, @@ -1042,7 +1024,7 @@ std::pair CenterLine::calcEndPoints2Lines(DrawVi // https://wiki.freecadweb.org/File:TD-CenterLineFlip.png for an illustration of the problem. // Thus we test this by a circulation test, see this post for a brief explanation: // https://forum.freecadweb.org/viewtopic.php?p=505733#p505615 - if (Circulation(l1p1, l1p2, l2p1) != Circulation(l1p2, l2p2, l2p1)) { + if (DrawUtil::circulation(l1p1, l1p2, l2p1) != DrawUtil::circulation(l1p2, l2p2, l2p1)) { Base::Vector3d temp; // reverse line 1 temp = l1p1; l1p1 = l1p2; diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index 98b5c4d512..6f7d1edb38 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -220,7 +220,6 @@ public: int mode, double ext, double m_hShift, double m_vShift, double rotate); - static bool Circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C); static std::pair calcEndPoints2Lines( TechDraw::DrawViewPart* partFeat, std::vector faceNames, diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 6fd468a36b..c686caefae 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -789,6 +789,15 @@ Base::Vector3d DrawUtil::getFaceCenter(TopoDS_Face f) return v; } +// test the circulation of the triangle A-B-C +bool DrawUtil::circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C) +{ + if (A.x * B.y + A.y * C.x + B.x * C.y - C.x * B.y - C.y * A.x - B.x * A.y > 0.0) + return true; + else + return false; +} + // Supplementary mathematical functions // ==================================== diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index d8633ae4ac..41cdc91805 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -121,6 +121,7 @@ class TechDrawExport DrawUtil { static PyObject* colorToPyTuple(App::Color color); static bool isCrazy(TopoDS_Edge e); static Base::Vector3d getFaceCenter(TopoDS_Face f); + static bool circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C); // Supplementary mathematical functions static int sgn(double x); diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index 01c6c5e872..2e9887175c 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -84,7 +84,6 @@ namespace TechDrawGui { //internal helper functions lineAttributes& _getActiveLineAttributes(); - bool _circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C); Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3); void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor); void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPart* objFeat, float factor); @@ -1845,14 +1844,6 @@ namespace TechDrawGui { return Base::Vector3d(c.x, c.y, 0.0); } - bool _circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C) { - // test the circulation of the triangle A-B-C - if (A.x * B.y + A.y * C.x + B.x * C.y - C.x * B.y - C.y * A.x - B.x * A.y > 0.0) - return true; - else - return false; - } - void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor) { // create the 3/4 arc symbolizing a thread from top seen double scale = objFeat->getScale(); @@ -1890,7 +1881,7 @@ namespace TechDrawGui { Base::Vector3d end0 = line0->points.at(1); Base::Vector3d start1 = line1->points.at(0); Base::Vector3d end1 = line1->points.at(1); - if (_circulation(start0, end0, start1) != _circulation(end0, end1, start1)) { + if (DrawUtil::circulation(start0, end0, start1) != DrawUtil::circulation(end0, end1, start1)) { Base::Vector3d help1 = start1; Base::Vector3d help2 = end1; start1 = help2;