libarea: make ChangeStartToNearest path breaking optinoal
This commit is contained in:
@@ -73,8 +73,8 @@ Point CArea::NearestPoint(const Point& p)const
|
|||||||
return best_point;
|
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;
|
for(std::list<CCurve>::iterator It=m_curves.begin(),ItNext=It;
|
||||||
It != m_curves.end(); It=ItNext)
|
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)
|
for(; It != m_curves.end(); ++It)
|
||||||
{
|
{
|
||||||
const CCurve& curve = *It;
|
const CCurve& curve = *It;
|
||||||
Point near_point = curve.NearestPoint(p);
|
Point near_point;
|
||||||
double dist = near_point.dist(p);
|
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)
|
if(dist < best_dist)
|
||||||
{
|
{
|
||||||
best_dist = dist;
|
best_dist = dist;
|
||||||
@@ -110,13 +124,16 @@ void CArea::ChangeStartToNearest(const Point *point, double min_dist) {
|
|||||||
}
|
}
|
||||||
if(ItBest->IsClosed()) {
|
if(ItBest->IsClosed()) {
|
||||||
ItBest->ChangeStart(best_point);
|
ItBest->ChangeStart(best_point);
|
||||||
}else if(ItBest->m_vertices.back().m_p.dist(best_point)<=min_dist) {
|
}else{
|
||||||
ItBest->Reverse();
|
double dfront = ItBest->m_vertices.front().m_p.dist(best_point);
|
||||||
}else if(ItBest->m_vertices.front().m_p.dist(best_point)>min_dist) {
|
double dback = ItBest->m_vertices.back().m_p.dist(best_point);
|
||||||
ItBest->Break(best_point);
|
if(min_dist>Point::tolerance && dfront>min_dist && dback>min_dist) {
|
||||||
m_curves.push_back(*ItBest);
|
ItBest->Break(best_point);
|
||||||
m_curves.back().ChangeEnd(best_point);
|
m_curves.push_back(*ItBest);
|
||||||
ItBest->ChangeStart(best_point);
|
m_curves.back().ChangeEnd(best_point);
|
||||||
|
ItBest->ChangeStart(best_point);
|
||||||
|
}else if(dfront>dback)
|
||||||
|
ItBest->Reverse();
|
||||||
}
|
}
|
||||||
curves.splice(curves.end(),m_curves,ItBest);
|
curves.splice(curves.end(),m_curves,ItBest);
|
||||||
p = curves.back().m_vertices.back().m_p;
|
p = curves.back().m_vertices.back().m_p;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
void CurveIntersections(const CCurve& curve, std::list<Point> &pts)const;
|
void CurveIntersections(const CCurve& curve, std::list<Point> &pts)const;
|
||||||
void InsideCurves(const CCurve& curve, std::list<CCurve> &curves_inside)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
|
//Avoid outside direct accessing static member variable because of Windows DLL issue
|
||||||
#define CAREA_PARAM_DECLARE(_type,_name) \
|
#define CAREA_PARAM_DECLARE(_type,_name) \
|
||||||
|
|||||||
Reference in New Issue
Block a user