|
@@ -53,10 +53,11 @@ struct vertex_list;
|
|
|
struct base_path:std::array<int,2>
|
|
|
{
|
|
|
int sid;
|
|
|
- base_path(int i1=-1,int i2=-1)
|
|
|
+ base_path(int i1=-1,int i2=-1,int _sid=0)
|
|
|
{
|
|
|
at(0)=i1;
|
|
|
at(1)=i2;
|
|
|
+ sid=_sid;
|
|
|
}
|
|
|
|
|
|
bool operator<(const base_path&o)const
|
|
@@ -107,7 +108,7 @@ struct vertex_list
|
|
|
return (((((unsigned)p.x)>>2)<<16) + (((unsigned)p.y)>>2));
|
|
|
}
|
|
|
|
|
|
- int find(const point&p,double x=1)const
|
|
|
+ int find(const point&p,double x=0.01)const
|
|
|
{
|
|
|
int rc=-1;
|
|
|
double t;
|
|
@@ -279,41 +280,40 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
|
|
|
point p1;
|
|
|
if(sscanf(vv,"%lf,%lf,%lf,%lf",&p0.x,&p0.y,&p1.x,&p1.y)==4)
|
|
|
{
|
|
|
- int p00=v.add(p0,0,999);
|
|
|
- int p10=v.add(p1,0,999);
|
|
|
+ point p_0=point::min(p0,p1);
|
|
|
+ point p_1=point::max(p0,p1);
|
|
|
|
|
|
- ret.push_back(base_path(p00,p10));
|
|
|
+ int p00=v.add(p_0,0,0);
|
|
|
+ int p10=v.add(p_1,0,0);
|
|
|
+
|
|
|
+ ret.push_back(base_path(p00,p10,0));
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}while(1);
|
|
|
|
|
|
-#ifdef __DEBUG__
|
|
|
- log_path(ret,v);
|
|
|
- printf("++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
-#endif
|
|
|
- std::sort(ret.begin(),ret.end());
|
|
|
-#ifdef __DEBUG__
|
|
|
- log_path(ret,v);
|
|
|
- printf("++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
-#endif
|
|
|
- ret.erase(std::unique(ret.begin(),ret.end()),ret.end());
|
|
|
-#ifdef __DEBUG__
|
|
|
- log_path(ret,v);
|
|
|
- printf("+++++++++++++++++nnnnn+++++++++++++++++++++++++++");
|
|
|
-#endif
|
|
|
-
|
|
|
- std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
|
|
|
- double arg=p1.arg(v)-p2.arg(v);
|
|
|
+ auto remove_dup=[](std::vector<base_path>&ret){
|
|
|
+ std::sort(ret.begin(),ret.end());
|
|
|
+ ret.erase(std::unique(ret.begin(),ret.end()),ret.end());
|
|
|
+ };
|
|
|
|
|
|
- if(fabs(arg)<0.1)
|
|
|
- {
|
|
|
- return v[p1[0]]<v[p2[0]];
|
|
|
- }
|
|
|
+ auto remove_empty=[](std::vector<base_path>&ret,vertex_list&v){
|
|
|
+ ret.erase(std::remove_if(ret.begin(),ret.end(),[&v](base_path&p){
|
|
|
+ point&p0=v[p[0]];
|
|
|
+ point&p1=v[p[1]];
|
|
|
+ return p0.dist(p1)<.00001;
|
|
|
+ }),
|
|
|
+ ret.end());
|
|
|
+ };
|
|
|
|
|
|
- return arg<0;
|
|
|
- });
|
|
|
+ auto sort_path=[](std::vector<base_path> & ret,vertex_list&v){
|
|
|
+ std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
|
|
|
+ return point::min(v[p1[0]],v[p1[1]]) < point::min(v[p2[0]],v[p2[1]]);
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
+ remove_dup(ret);
|
|
|
+ sort_path(ret,v);
|
|
|
log_path(ret,v,"合并前");
|
|
|
//合并相同
|
|
|
for(int i=0,len=ret.size();i<len;i++)
|
|
@@ -322,16 +322,22 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
|
|
|
for(int j=i+1;j<len;j++)
|
|
|
{
|
|
|
line_v lj=ret[j].as_line(v);
|
|
|
- if(!lj.is_same(li,2.5))
|
|
|
+ if(!lj.is_same(li,1)) //li线段两个点在lj直线上
|
|
|
continue;
|
|
|
|
|
|
- line_v ij=lj.projection(li);
|
|
|
+ line_v ij=lj.projection(li);//重叠
|
|
|
|
|
|
if(ij.empty())
|
|
|
continue;
|
|
|
|
|
|
- point p0=point::min(v[ret[j][0]],v[ret[i][0]]);
|
|
|
- point p1=point::max(v[ret[j][1]],v[ret[i][1]]);
|
|
|
+
|
|
|
+
|
|
|
+ point p0=li.as_line().projection(v[ret[j][0]]);
|
|
|
+ point p1=li.as_line().projection(v[ret[j][1]]);
|
|
|
+
|
|
|
+
|
|
|
+ p0=point::min(p0,v[ret[i][0]]);
|
|
|
+ p1=point::max(p1,v[ret[i][1]]);
|
|
|
|
|
|
ret[j][0]=v.add(p0,0);
|
|
|
ret[j][1]=v.add(p1,0);
|
|
@@ -346,17 +352,7 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
|
|
|
return p[0]==0||p[1]==0;
|
|
|
}),ret.end());
|
|
|
|
|
|
- std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
|
|
|
- double arg=p1.arg(v)-p2.arg(v);
|
|
|
-
|
|
|
- if(fabs(arg)<0.1)
|
|
|
- {
|
|
|
- return v[p1[0]]<v[p2[0]];
|
|
|
- }
|
|
|
-
|
|
|
- return arg<0;
|
|
|
- });
|
|
|
-
|
|
|
+ sort_path(ret,v);
|
|
|
log_path(ret,v,"合并后");
|
|
|
|
|
|
//非路径交点配置
|
|
@@ -427,12 +423,28 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
|
|
|
p0[i].push_back(id);
|
|
|
p0[j].push_back(id);
|
|
|
}
|
|
|
-
|
|
|
p0[i].push_back(ret[i][1]);
|
|
|
|
|
|
- std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){
|
|
|
- return v[i0]<v[i1];
|
|
|
- });
|
|
|
+ std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){ return v[i0]<v[i1]; });
|
|
|
+#if 0
|
|
|
+ if(p0[i].size())
|
|
|
+ {
|
|
|
+ for(int v=0;v<2;v++)
|
|
|
+ {
|
|
|
+ if(v[ret[i][v]].dist(v[p0[i].front()])<3)
|
|
|
+ continue;
|
|
|
+ if(v[ret[i][v]].dist(v[p0[i].back()])<3)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ p0[i].push_back(ret[i][v]);
|
|
|
+ std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){ return v[i0]<v[i1]; });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){ return v[i0]<v[i1]; });
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
auto it=std::unique(p0[i].begin(),p0[i].end());
|
|
|
p0[i].erase(it,p0[i].end());
|
|
@@ -444,27 +456,9 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ret2.erase(std::remove_if(ret2.begin(),ret2.end(),[&v](base_path&p){
|
|
|
- point&p0=v[p[0]];
|
|
|
- point&p1=v[p[1]];
|
|
|
-
|
|
|
- //return p0.dist(p1)<0.1 || p0.empty() || p1.empty();
|
|
|
- return p0.dist(p1)<1;
|
|
|
- }),ret2.end());
|
|
|
-
|
|
|
- std::sort(ret2.begin(),ret2.end());
|
|
|
- ret2.erase(std::unique(ret2.begin(),ret2.end()),ret2.end());
|
|
|
-
|
|
|
- std::sort(ret2.begin(),ret2.end(),[&v](const base_path&p1,const base_path&p2){
|
|
|
- double arg=p1.arg(v)-p2.arg(v);
|
|
|
-
|
|
|
- if(fabs(arg)<0.1)
|
|
|
- {
|
|
|
- return v[p1[0]]<v[p2[0]];
|
|
|
- }
|
|
|
-
|
|
|
- return arg<0;
|
|
|
- });
|
|
|
+ remove_empty(ret2,v);
|
|
|
+ remove_dup(ret2);
|
|
|
+ sort_path(ret,v);
|
|
|
log_path(ret2,v,"拆分后");
|
|
|
|
|
|
return std::move(ret2);
|