Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libarea: make ChangeStartToNearest path breaking optinoal
  • Loading branch information
realthunder committed Jan 31, 2017
1 parent 94c4cec commit c3293f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 28 additions & 11 deletions src/Mod/Path/libarea/Area.cpp
Expand Up @@ -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<CCurve>::iterator It=m_curves.begin(),ItNext=It;
It != m_curves.end(); It=ItNext)
{
Expand All @@ -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(d1<d2) {
dist = d1;
near_point = curve.m_vertices.front().m_p;
}else{
dist = d2;
near_point = curve.m_vertices.back().m_p;
}
}else{
near_point = curve.NearestPoint(p);
dist = near_point.dist(p);
}
if(dist < best_dist)
{
best_dist = dist;
Expand All @@ -110,13 +124,16 @@ void CArea::ChangeStartToNearest(const Point *point, double min_dist) {
}
if(ItBest->IsClosed()) {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/libarea/Area.h
Expand Up @@ -85,7 +85,7 @@ class CArea
void CurveIntersections(const CCurve& curve, std::list<Point> &pts)const;
void InsideCurves(const CCurve& curve, std::list<CCurve> &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) \
Expand Down

0 comments on commit c3293f0

Please sign in to comment.