Skip to content

Commit

Permalink
[TD]fix torus render (fix FreeCAD#16646)
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Sep 20, 2024
1 parent a47800d commit 1d42d89
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Mod/TechDraw/App/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,19 +1644,24 @@ TopoDS_Edge GeometryUtils::asCircle(TopoDS_Edge splineEdge, bool& arc)
gp_Pnt endPoint = curveAdapt.Value(lastParam);

arc = true;
if (startPoint.IsEqual(endPoint, 0.001)) { //more reliable than IsClosed flag
arc = false;
}
double midRange = (lastParam + firstParam) / 2;
gp_Pnt midPoint = curveAdapt.Value(midRange);
Handle(Geom_Circle) circle3Points = GC_MakeCircle(startPoint, midPoint, endPoint);

if (circle3Points.IsNull()) {
return {};
}
if (startPoint.IsEqual(endPoint, 0.001)) { //more reliable than IsClosed flag
arc = false;
// can not use the start and end points since they are the same and that will give us only
// 2 of the 3 points we need. Q: why did this work sometimes?
// Q: do we need to account for reversed parameter range? we don't use reversed edges much.
auto parmRange = lastParam - firstParam;
auto lowParm = parmRange * 0.25;
auto lowPoint = curveAdapt.Value(lowParm);
auto highParm = parmRange* 0.75;
auto highPoint = curveAdapt.Value(highParm);
Handle(Geom_Circle) circle3Points = GC_MakeCircle(lowPoint, midPoint, highPoint);

if (circle3Points.IsNull()) {
return {};
}

if (!arc) {
// whole circle
return BRepBuilderAPI_MakeEdge(circle3Points);
}

Expand Down

0 comments on commit 1d42d89

Please sign in to comment.