From 0fd02a4c115ce2488624a86fa670c7e9ab39910c Mon Sep 17 00:00:00 2001 From: Tomas Pavlicek Date: Mon, 21 Jun 2021 15:20:52 +0200 Subject: [PATCH 1/2] TechDraw - Add edge midpoint cosmetic vertex fix --- src/Mod/TechDraw/App/Geometry.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 13a5aa9133..a44013bc21 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -326,16 +326,19 @@ Base::Vector3d BaseGeom::getEndPoint() Base::Vector3d BaseGeom::getMidPoint() { - Base::Vector3d result; - BRepAdaptor_Curve adapt(occEdge); - double u = adapt.FirstParameter(); - double v = adapt.LastParameter(); - double range = v - u; - double midParm = u + (range / 2.0); - BRepLProp_CLProps prop(adapt,midParm,0,Precision::Confusion()); - const gp_Pnt& pt = prop.Value(); - result = Base::Vector3d(pt.X(),pt.Y(), pt.Z()); - return result; + BRepAdaptor_Curve curve(occEdge); + double midParam = (curve.FirstParameter() + curve.LastParameter())/2.0; + + GCPnts_AbscissaPoint abscissa(Precision::Confusion(), curve, GCPnts_AbscissaPoint::Length(curve)/2.0, + curve.FirstParameter()); + if (abscissa.IsDone()) { + midParam = abscissa.Parameter(); + } + + BRepLProp_CLProps props(curve, midParam, 0, Precision::Confusion()); + const gp_Pnt &point = props.Value(); + + return Base::Vector3d(point.X(), point.Y(), point.Z()); } std::vector BaseGeom::getQuads() From be19f397f3dfb8308a0276e186ec7a8fa0018122 Mon Sep 17 00:00:00 2001 From: Tomas Pavlicek Date: Thu, 24 Jun 2021 20:47:10 +0200 Subject: [PATCH 2/2] TechDraw - Add edge midpoint cosmetic vertex fix - added comments --- src/Mod/TechDraw/App/Geometry.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index a44013bc21..b6c3637137 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -326,15 +326,24 @@ Base::Vector3d BaseGeom::getEndPoint() Base::Vector3d BaseGeom::getMidPoint() { + // Midpoint calculation - additional details here: https://forum.freecadweb.org/viewtopic.php?f=35&t=59582 + BRepAdaptor_Curve curve(occEdge); + + // As default, set the midpoint curve parameter value by simply averaging start point and end point values double midParam = (curve.FirstParameter() + curve.LastParameter())/2.0; + // GCPnts_AbscissaPoint allows us to compute the parameter value depending on the distance along a curve. + // In this case we want the curve parameter value for the half of the whole curve length, + // thus GCPnts_AbscissaPoint::Length(curve)/2 is the distance to go from the start point. GCPnts_AbscissaPoint abscissa(Precision::Confusion(), curve, GCPnts_AbscissaPoint::Length(curve)/2.0, curve.FirstParameter()); if (abscissa.IsDone()) { + // The computation was successful - otherwise keep the average, it is better than nothing midParam = abscissa.Parameter(); } + // Now compute coordinates of the point on curve for curve parameter value equal to midParam BRepLProp_CLProps props(curve, midParam, 0, Precision::Confusion()); const gp_Pnt &point = props.Value();