From 1d61ed187c9633702818c6cc5d7a1f07dd052ca8 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 27 May 2023 21:35:01 +0200 Subject: [PATCH] Sketcher: Fix bug angle via point visualisation =============================================== Issue description: https://forum.freecad.org/viewtopic.php?f=3&t=70325 https://github.com/FreeCAD/FreeCAD/issues/7520 The general algorithm to calculate normals miserably fails when the curve is a line segment and the point through which the normal to a curve is to be drawn is colinear with the line segment. The solution is to provide specific code for this corner case. fixes #7520 --- .../Gui/EditModeConstraintCoinManager.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index fb2ffcb39e..2268ff188b 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -143,17 +143,25 @@ Restart: auto geom = geolistfacade.getGeometryFromGeoId(geoid); auto curve = dynamic_cast(geom); - Base::Vector3d normal; - try { - if (!(curve && curve->normalAt(pointoncurve, normal))) { + auto line = dynamic_cast(curve); + + if (line) { + Base::Vector3d linedir = line->getEndPoint() - line->getStartPoint(); + return Base::Vector3d(-linedir.y, linedir.x, 0); + } + else { + Base::Vector3d normal; + try { + if (!(curve && curve->normalAt(pointoncurve, normal))) { + normal = Base::Vector3d(1, 0, 0); + } + } + catch (const Base::CADKernelError&) { normal = Base::Vector3d(1, 0, 0); } - } - catch (const Base::CADKernelError&) { - normal = Base::Vector3d(1, 0, 0); - } - return normal; + return normal; + } }; // go through the constraints and update the position