From 7d0f8e2fa9335f4074dde0852cc3bcc5aaf3a6f2 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 22 Jun 2019 15:19:13 +0200 Subject: [PATCH] Sketcher: Polyline snap arc to 45 degrees bug fix ================================================= fixes #3974 Snapping to 45 degrees during arc creation (hold ctrl during an arc within a polyline), resulted in reduced precision, because Gui::Command::doCommand %f defaults only to six decimal positions, which is a poor representation in radians of, for example, 90 degrees. A work-around could have been to hardcode a higher number of decimals, as in %0.Xf. However, I do not like such magic numbers. The solution chosen is to use an App.Quantity object using as units degrees, which leads to no loss of precision. --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index e41652f884..31ad52c730 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -1155,10 +1155,14 @@ public: if(SnapMode == SNAP_MODE_45Degree && Mode != STATUS_Close) { // -360, -315, -270, -225, -180, -135, -90, -45, 0, 45, 90, 135, 180, 225, 270, 315, 360 // N/A, a, perp, a, par, a,perp, a,N/A, a,perp, a, par, a,perp, a, N/A + + // #3974: if in radians, the printf %f defaults to six decimals, which leads to loss of precision + double arcAngle = abs(round( (endAngle - startAngle) / (M_PI/4)) * 45); // in degrees + Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%i,%f)) ", + "App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%i,App.Units.Quantity('%f deg'))) ", sketchgui->getObject()->getNameInDocument(), - lastCurve, abs(endAngle-startAngle)); + lastCurve, arcAngle); } if (Mode == STATUS_Close) { // close the loop by constrain to the first curve point