From 9c72d78b7be5a7225ba99b71e33fe69f331fa60a Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 23 Feb 2018 08:50:53 +0800 Subject: [PATCH] Path.Area: arc fix to work around OCCT bug --- src/Mod/Path/App/Area.cpp | 60 +++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index 13566bd1f1..a1a3f2a752 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -1490,7 +1490,7 @@ std::vector > Area::makeSections( } } FC_TIME_LOG(t,"makeSection count: " << sections.size()<<", total"); - return sections; + return std::move(sections); } TopoDS_Shape Area::getPlane(gp_Trsf *trsf) { @@ -2073,29 +2073,47 @@ TopoDS_Wire Area::toShape(const CCurve &_c, const gp_Trsf *trsf, int reorient) { if(pnext.SquareDistance(pt) Precision::Confusion()) { - double d = pt.Distance(pnext); - double q = sqrt(r*r - d*d*0.25); - double x = (pt.X()+pnext.X())*0.5; - double y = (pt.Y()+pnext.Y())*0.5; - double dx = q*(pt.Y()-pnext.Y())/d; - double dy = q*(pnext.X()-pt.X())/d; - gp_Pnt newCenter(x + dx, y + dy,0); - if(IsLeft(pt,pnext,center) != IsLeft(pt,pnext,newCenter)) { - newCenter.SetX(x - dx); - newCenter.SetY(y - dy); + bool fix_arc = fabs(r-r2) > Precision::Confusion(); + while(1) { + if(fix_arc) { + double d = pt.Distance(pnext); + double rr = r*r; + double dd = d*d*0.25; + double q = rr<=dd?0:sqrt(rr-dd); + double x = (pt.X()+pnext.X())*0.5; + double y = (pt.Y()+pnext.Y())*0.5; + double dx = q*(pt.Y()-pnext.Y())/d; + double dy = q*(pnext.X()-pt.X())/d; + gp_Pnt newCenter(x + dx, y + dy,0); + if(IsLeft(pt,pnext,center) != IsLeft(pt,pnext,newCenter)) { + newCenter.SetX(x - dx); + newCenter.SetY(y - dy); + } + AREA_WARN("Arc correction: "<"<"<0 && d>max_dist) break; } - return wires; + return std::move(wires); } }; @@ -2783,7 +2801,7 @@ std::list Area::sortWires(const std::list &shapes, foreachSubshape(shape, WireOrienter(wires,dir,orientation,direction), TopAbs_WIRE); } - return wires; + return std::move(wires); } ShapeParams rparams(abscissa,nearest_k>0?nearest_k:1,orientation,direction); @@ -2965,7 +2983,7 @@ std::list Area::sortWires(const std::list &shapes, FC_DURATION_LOG(rparams.rd,"rtree clean"); FC_DURATION_LOG(rparams.xd,"BRepExtrema"); FC_TIME_LOG(t,"sortWires total"); - return wires; + return std::move(wires); } static inline void addParameter(bool verbose, Command &cmd, const char *name,