From c3293f00be889affcee5fb166b6fc8a3848459ce Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Tue, 31 Jan 2017 19:08:39 +0800 Subject: [PATCH] libarea: make ChangeStartToNearest path breaking optinoal --- src/Mod/Path/libarea/Area.cpp | 39 +++++++++++++++++++++++++---------- src/Mod/Path/libarea/Area.h | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/Mod/Path/libarea/Area.cpp b/src/Mod/Path/libarea/Area.cpp index c39bde2e49..a4e5bf29d9 100644 --- a/src/Mod/Path/libarea/Area.cpp +++ b/src/Mod/Path/libarea/Area.cpp @@ -73,8 +73,8 @@ Point CArea::NearestPoint(const Point& p)const return best_point; } -void CArea::ChangeStartToNearest(const Point *point, double min_dist) { - +void CArea::ChangeStartToNearest(const Point *point, double min_dist) +{ for(std::list::iterator It=m_curves.begin(),ItNext=It; It != m_curves.end(); It=ItNext) { @@ -99,8 +99,22 @@ void CArea::ChangeStartToNearest(const Point *point, double min_dist) { for(; It != m_curves.end(); ++It) { const CCurve& curve = *It; - Point near_point = curve.NearestPoint(p); - double dist = near_point.dist(p); + Point near_point; + double dist; + if(min_dist>Point::tolerance && !curve.IsClosed()) { + double d1 = curve.m_vertices.front().m_p.dist(p); + double d2 = curve.m_vertices.back().m_p.dist(p); + if(d1IsClosed()) { ItBest->ChangeStart(best_point); - }else if(ItBest->m_vertices.back().m_p.dist(best_point)<=min_dist) { - ItBest->Reverse(); - }else if(ItBest->m_vertices.front().m_p.dist(best_point)>min_dist) { - ItBest->Break(best_point); - m_curves.push_back(*ItBest); - m_curves.back().ChangeEnd(best_point); - ItBest->ChangeStart(best_point); + }else{ + double dfront = ItBest->m_vertices.front().m_p.dist(best_point); + double dback = ItBest->m_vertices.back().m_p.dist(best_point); + if(min_dist>Point::tolerance && dfront>min_dist && dback>min_dist) { + ItBest->Break(best_point); + m_curves.push_back(*ItBest); + m_curves.back().ChangeEnd(best_point); + ItBest->ChangeStart(best_point); + }else if(dfront>dback) + ItBest->Reverse(); } curves.splice(curves.end(),m_curves,ItBest); p = curves.back().m_vertices.back().m_p; diff --git a/src/Mod/Path/libarea/Area.h b/src/Mod/Path/libarea/Area.h index ca9a641527..88e8fca5cf 100644 --- a/src/Mod/Path/libarea/Area.h +++ b/src/Mod/Path/libarea/Area.h @@ -85,7 +85,7 @@ public: void CurveIntersections(const CCurve& curve, std::list &pts)const; void InsideCurves(const CCurve& curve, std::list &curves_inside)const; - void ChangeStartToNearest(const Point *point=NULL, double min_dist=1.0); + void ChangeStartToNearest(const Point *pstart=NULL, double min_dist=1.0); //Avoid outside direct accessing static member variable because of Windows DLL issue #define CAREA_PARAM_DECLARE(_type,_name) \