From 7d9cfeb2c5032aa5edbae6cf10213aaec3ee97f9 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 14 Apr 2020 15:42:48 +0200 Subject: [PATCH] Sketcher: Fix trim ================== https://forum.freecadweb.org/viewtopic.php?p=387303#p387303 1. Trim had a bug that the type of the constraint on the second point was equal to the first one regardless of the situation. 2. Trim did not have support for checking whether points were close to the edge and relied on preexisting constraints. --- src/Mod/Sketcher/App/SketchObject.cpp | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 443840ab3f..eeb4061446 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1939,6 +1939,17 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) secondPos = constr->FirstPos; } }; + + auto isPointAtPosition = [this] (int GeoId1, PointPos pos1, Base::Vector3d point) { + + Base::Vector3d pp = getPoint(GeoId1,pos1); + + if( (point-pp).Length() < Precision::Confusion() ) + return true; + + return false; + + }; Part::Geometry *geo = geomlist[GeoId]; if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { @@ -2128,6 +2139,26 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; + + // check first if start and end points are within a confusion tolerance + if(isPointAtPosition(GeoId1, Sketcher::start, point1)) { + constrType1 = Sketcher::Coincident; + secondPos1 = Sketcher::start; + } + else if(isPointAtPosition(GeoId1, Sketcher::end, point1)) { + constrType1 = Sketcher::Coincident; + secondPos1 = Sketcher::end; + } + + if(isPointAtPosition(GeoId2, Sketcher::start, point2)) { + constrType2 = Sketcher::Coincident; + secondPos2 = Sketcher::start; + } + else if(isPointAtPosition(GeoId2, Sketcher::end, point2)) { + constrType2 = Sketcher::Coincident; + secondPos2 = Sketcher::end; + } + for (std::vector::const_iterator it=constraints.begin(); it != constraints.end(); ++it) { Constraint *constr = *(it); @@ -2162,6 +2193,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) newConstr->SecondPos = Sketcher::none; // Add Second Constraint + newConstr->Type = constrType2; newConstr->First = GeoId; newConstr->FirstPos = end; newConstr->Second = GeoId2;