diff options
Diffstat (limited to 'source/blender/blenlib/intern/scanfill.c')
-rw-r--r-- | source/blender/blenlib/intern/scanfill.c | 299 |
1 files changed, 153 insertions, 146 deletions
diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 420481f165b..90031d961c3 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -72,7 +72,8 @@ static int callLocalInterruptCallBack(void) { if (BLI_localInterruptCallBack) { return BLI_localInterruptCallBack(); - } else { + } + else { return 0; } } @@ -110,10 +111,10 @@ static int vergscdata(const void *a1, const void *a2) { const ScanFillVertLink *x1=a1,*x2=a2; - if( x1->v1->co[coy] < x2->v1->co[coy] ) return 1; - else if( x1->v1->co[coy] > x2->v1->co[coy]) return -1; - else if( x1->v1->co[cox] > x2->v1->co[cox] ) return 1; - else if( x1->v1->co[cox] < x2->v1->co[cox]) return -1; + if ( x1->v1->co[coy] < x2->v1->co[coy] ) return 1; + else if ( x1->v1->co[coy] > x2->v1->co[coy]) return -1; + else if ( x1->v1->co[cox] > x2->v1->co[cox] ) return 1; + else if ( x1->v1->co[cox] < x2->v1->co[cox]) return -1; return 0; } @@ -122,10 +123,10 @@ static int vergpoly(const void *a1, const void *a2) { const PolyFill *x1=a1, *x2=a2; - if( x1->min[cox] > x2->min[cox] ) return 1; - else if( x1->min[cox] < x2->min[cox] ) return -1; - else if( x1->min[coy] > x2->min[coy] ) return 1; - else if( x1->min[coy] < x2->min[coy] ) return -1; + if ( x1->min[cox] > x2->min[cox] ) return 1; + else if ( x1->min[cox] < x2->min[cox] ) return -1; + else if ( x1->min[coy] > x2->min[coy] ) return 1; + else if ( x1->min[coy] < x2->min[coy] ) return -1; return 0; } @@ -153,7 +154,7 @@ static void *mem_element_new(int size) size = (size + 3 ) & ~3; /* allocate in units of 4 */ - if(melem__cur && (size + melem__offs < MEM_ELEM_BLOCKSIZE)) { + if (melem__cur && (size + melem__offs < MEM_ELEM_BLOCKSIZE)) { void *adr= (void *) (melem__cur->data+melem__offs); melem__offs+= size; return adr; @@ -171,13 +172,13 @@ static void mem_element_reset(int keep_first) { struct mem_elements *first; - if((first= melem__lb.first)) { /* can be false if first fill fails */ + if ((first= melem__lb.first)) { /* can be false if first fill fails */ if (keep_first) { BLI_remlink(&melem__lb, first); } melem__cur= melem__lb.first; - while(melem__cur) { + while (melem__cur) { MEM_freeN(melem__cur->data); melem__cur= melem__cur->next; } @@ -261,20 +262,20 @@ static int boundisect(PolyFill *pf2, PolyFill *pf1) /* has pf2 been touched (intersected) by pf1 ? with bounding box */ /* test first if polys exist */ - if(pf1->edges==0 || pf2->edges==0) return 0; + if (pf1->edges==0 || pf2->edges==0) return 0; - if(pf2->max[cox] < pf1->min[cox] ) return 0; - if(pf2->max[coy] < pf1->min[coy] ) return 0; + if (pf2->max[cox] < pf1->min[cox] ) return 0; + if (pf2->max[coy] < pf1->min[coy] ) return 0; - if(pf2->min[cox] > pf1->max[cox] ) return 0; - if(pf2->min[coy] > pf1->max[coy] ) return 0; + if (pf2->min[cox] > pf1->max[cox] ) return 0; + if (pf2->min[coy] > pf1->max[coy] ) return 0; /* join */ - if(pf2->max[cox]<pf1->max[cox]) pf2->max[cox]= pf1->max[cox]; - if(pf2->max[coy]<pf1->max[coy]) pf2->max[coy]= pf1->max[coy]; + if (pf2->max[cox]<pf1->max[cox]) pf2->max[cox]= pf1->max[cox]; + if (pf2->max[coy]<pf1->max[coy]) pf2->max[coy]= pf1->max[coy]; - if(pf2->min[cox]>pf1->min[cox]) pf2->min[cox]= pf1->min[cox]; - if(pf2->min[coy]>pf1->min[coy]) pf2->min[coy]= pf1->min[coy]; + if (pf2->min[cox]>pf1->min[cox]) pf2->min[cox]= pf1->min[cox]; + if (pf2->min[coy]>pf1->min[coy]) pf2->min[coy]= pf1->min[coy]; return 1; } @@ -287,12 +288,12 @@ static void mergepolysSimp(PolyFill *pf1, PolyFill *pf2) /* add pf2 to pf1 */ /* replace old poly numbers */ eve= fillvertbase.first; - while(eve) { - if(eve->poly_nr == pf2->nr) eve->poly_nr = pf1->nr; + while (eve) { + if (eve->poly_nr == pf2->nr) eve->poly_nr = pf1->nr; eve= eve->next; } eed= filledgebase.first; - while(eed) { + while (eed) { if (eed->poly_nr == pf2->nr) eed->poly_nr = pf1->nr; eed= eed->next; } @@ -311,10 +312,10 @@ static short testedgeside(const float v1[3], const float v2[3], const float v3[3 inp= (v2[cox]-v1[cox])*(v1[coy]-v3[coy]) +(v1[coy]-v2[coy])*(v1[cox]-v3[cox]); - if(inp < 0.0f) return 0; - else if(inp==0) { - if(v1[cox]==v3[cox] && v1[coy]==v3[coy]) return 0; - if(v2[cox]==v3[cox] && v2[coy]==v3[coy]) return 0; + if (inp < 0.0f) return 0; + else if (inp==0) { + if (v1[cox]==v3[cox] && v1[coy]==v3[coy]) return 0; + if (v2[cox]==v3[cox] && v2[coy]==v3[coy]) return 0; } return 1; } @@ -325,7 +326,7 @@ static short addedgetoscanvert(ScanFillVertLink *sc, ScanFillEdge *eed) ScanFillEdge *ed; float fac,fac1,x,y; - if(sc->first==0) { + if (sc->first==0) { sc->first= sc->last= eed; eed->prev= eed->next=0; return 1; @@ -335,28 +336,28 @@ static short addedgetoscanvert(ScanFillVertLink *sc, ScanFillEdge *eed) y= eed->v1->co[coy]; fac1= eed->v2->co[coy]-y; - if(fac1==0.0f) { + if (fac1==0.0f) { fac1= 1.0e10f*(eed->v2->co[cox]-x); } else fac1= (x-eed->v2->co[cox])/fac1; ed= sc->first; - while(ed) { + while (ed) { - if(ed->v2==eed->v2) return 0; + if (ed->v2==eed->v2) return 0; fac= ed->v2->co[coy]-y; - if(fac==0.0f) { + if (fac==0.0f) { fac= 1.0e10f*(ed->v2->co[cox]-x); } else fac= (x-ed->v2->co[cox])/fac; - if(fac>fac1) break; + if (fac>fac1) break; ed= ed->next; } - if(ed) BLI_insertlinkbefore((ListBase *)&(sc->first), ed, eed); + if (ed) BLI_insertlinkbefore((ListBase *)&(sc->first), ed, eed); else BLI_addtail((ListBase *)&(sc->first),eed); return 1; @@ -371,14 +372,14 @@ static ScanFillVertLink *addedgetoscanlist(ScanFillEdge *eed, int len) ScanFillVert *eve; /* which vert is left-top? */ - if(eed->v1->co[coy] == eed->v2->co[coy]) { - if(eed->v1->co[cox] > eed->v2->co[cox]) { + if (eed->v1->co[coy] == eed->v2->co[coy]) { + if (eed->v1->co[cox] > eed->v2->co[cox]) { eve= eed->v1; eed->v1= eed->v2; eed->v2= eve; } } - else if(eed->v1->co[coy] < eed->v2->co[coy]) { + else if (eed->v1->co[coy] < eed->v2->co[coy]) { eve= eed->v1; eed->v1= eed->v2; eed->v2= eve; @@ -388,8 +389,8 @@ static ScanFillVertLink *addedgetoscanlist(ScanFillEdge *eed, int len) sc= (ScanFillVertLink *)bsearch(&scsearch,scdata,len, sizeof(ScanFillVertLink), vergscdata); - if(sc==0) printf("Error in search edge: %p\n", (void *)eed); - else if(addedgetoscanvert(sc,eed)==0) return sc; + if (sc==0) printf("Error in search edge: %p\n", (void *)eed); + else if (addedgetoscanvert(sc,eed)==0) return sc; return 0; } @@ -399,22 +400,24 @@ static short boundinsideEV(ScanFillEdge *eed, ScanFillVert *eve) { float minx,maxx,miny,maxy; - if(eed->v1->co[cox]<eed->v2->co[cox]) { + if (eed->v1->co[cox]<eed->v2->co[cox]) { minx= eed->v1->co[cox]; maxx= eed->v2->co[cox]; - } else { + } + else { minx= eed->v2->co[cox]; maxx= eed->v1->co[cox]; } - if(eve->co[cox]>=minx && eve->co[cox]<=maxx) { - if(eed->v1->co[coy]<eed->v2->co[coy]) { + if (eve->co[cox]>=minx && eve->co[cox]<=maxx) { + if (eed->v1->co[coy]<eed->v2->co[coy]) { miny= eed->v1->co[coy]; maxy= eed->v2->co[coy]; - } else { + } + else { miny= eed->v2->co[coy]; maxy= eed->v1->co[coy]; } - if(eve->co[coy]>=miny && eve->co[coy]<=maxy) return 1; + if (eve->co[coy]>=miny && eve->co[coy]<=maxy) return 1; } return 0; } @@ -430,30 +433,30 @@ static void testvertexnearedge(void) float dist,vec1[2],vec2[2],vec3[2]; eve= fillvertbase.first; - while(eve) { - if(eve->h==1) { + while (eve) { + if (eve->h==1) { vec3[0]= eve->co[cox]; vec3[1]= eve->co[coy]; /* find the edge which has vertex eve */ ed1= filledgebase.first; - while(ed1) { - if(ed1->v1==eve || ed1->v2==eve) break; + while (ed1) { + if (ed1->v1==eve || ed1->v2==eve) break; ed1= ed1->next; } - if(ed1->v1==eve) { + if (ed1->v1==eve) { ed1->v1= ed1->v2; ed1->v2= eve; } eed= filledgebase.first; - while(eed) { + while (eed) { if (eve != eed->v1 && eve != eed->v2 && eve->poly_nr == eed->poly_nr) { - if(compare_v3v3(eve->co,eed->v1->co, COMPLIMIT)) { + if (compare_v3v3(eve->co,eed->v1->co, COMPLIMIT)) { ed1->v2= eed->v1; eed->v1->h++; eve->h= 0; break; } - else if(compare_v3v3(eve->co,eed->v2->co, COMPLIMIT)) { + else if (compare_v3v3(eve->co,eed->v2->co, COMPLIMIT)) { ed1->v2= eed->v2; eed->v2->h++; eve->h= 0; @@ -464,9 +467,9 @@ static void testvertexnearedge(void) vec1[1]= eed->v1->co[coy]; vec2[0]= eed->v2->co[cox]; vec2[1]= eed->v2->co[coy]; - if(boundinsideEV(eed,eve)) { + if (boundinsideEV(eed,eve)) { dist= dist_to_line_v2(vec1,vec2,vec3); - if(dist<(float)COMPLIMIT) { + if (dist<(float)COMPLIMIT) { /* new edge */ ed1= BLI_addfilledge(eed->v1, eve); @@ -497,7 +500,7 @@ static void splitlist(ListBase *tempve, ListBase *temped, short nr) BLI_movelisttolist(temped,&filledgebase); eve= tempve->first; - while(eve) { + while (eve) { nextve= eve->next; if (eve->poly_nr == nr) { BLI_remlink(tempve,eve); @@ -506,9 +509,9 @@ static void splitlist(ListBase *tempve, ListBase *temped, short nr) eve= nextve; } eed= temped->first; - while(eed) { + while (eed) { nexted= eed->next; - if(eed->poly_nr==nr) { + if (eed->poly_nr==nr) { BLI_remlink(temped,eed); BLI_addtail(&filledgebase,eed); } @@ -532,12 +535,12 @@ static int scanfill(PolyFill *pf) #if 0 verts= pf->verts; eve= fillvertbase.first; - while(eve) { + while (eve) { printf("vert: %x co: %f %f\n",eve,eve->co[cox],eve->co[coy]); eve= eve->next; } eed= filledgebase.first; - while(eed) { + while (eed) { printf("edge: %x verts: %x %x\n",eed,eed->v1,eed->v2); eed= eed->next; } @@ -545,18 +548,18 @@ static int scanfill(PolyFill *pf) /* STEP 0: remove zero sized edges */ eed= filledgebase.first; - while(eed) { - if(eed->v1->co[cox]==eed->v2->co[cox]) { - if(eed->v1->co[coy]==eed->v2->co[coy]) { - if(eed->v1->f==255 && eed->v2->f!=255) { + while (eed) { + if (eed->v1->co[cox]==eed->v2->co[cox]) { + if (eed->v1->co[coy]==eed->v2->co[coy]) { + if (eed->v1->f==255 && eed->v2->f!=255) { eed->v2->f= 255; eed->v2->tmp.v= eed->v1->tmp.v; } - else if(eed->v2->f==255 && eed->v1->f!=255) { + else if (eed->v2->f==255 && eed->v1->f!=255) { eed->v1->f= 255; eed->v1->tmp.v= eed->v2->tmp.v; } - else if(eed->v2->f==255 && eed->v1->f==255) { + else if (eed->v2->f==255 && eed->v1->f==255) { eed->v1->tmp.v= eed->v2->tmp.v; } else { @@ -574,7 +577,7 @@ static int scanfill(PolyFill *pf) sc= scdata= (ScanFillVertLink *)MEM_callocN(pf->verts*sizeof(ScanFillVertLink),"Scanfill1"); eve= fillvertbase.first; verts= 0; - while(eve) { + while (eve) { if (eve->poly_nr == nr) { if (eve->f != 255) { verts++; @@ -589,7 +592,7 @@ static int scanfill(PolyFill *pf) qsort(scdata, verts, sizeof(ScanFillVertLink), vergscdata); eed= filledgebase.first; - while(eed) { + while (eed) { nexted= eed->next; BLI_remlink(&filledgebase,eed); /* This code is for handling zero-length edges that get @@ -597,26 +600,26 @@ static int scanfill(PolyFill *pf) * fix trunk bug #4544, so if that comes back, this code * may need some work, or there will have to be a better * fix to #4544. */ - if(eed->v1->f==255) { + if (eed->v1->f==255) { v1= eed->v1; - while((eed->v1->f == 255) && (eed->v1->tmp.v != v1)) + while ((eed->v1->f == 255) && (eed->v1->tmp.v != v1)) eed->v1 = eed->v1->tmp.v; } - if(eed->v2->f==255) { + if (eed->v2->f==255) { v2= eed->v2; - while((eed->v2->f == 255) && (eed->v2->tmp.v != v2)) + while ((eed->v2->f == 255) && (eed->v2->tmp.v != v2)) eed->v2 = eed->v2->tmp.v; } - if(eed->v1!=eed->v2) addedgetoscanlist(eed,verts); + if (eed->v1!=eed->v2) addedgetoscanlist(eed,verts); eed= nexted; } #if 0 sc= scdata; - for(a=0;a<verts;a++) { + for (a=0;a<verts;a++) { printf("\nscvert: %x\n",sc->v1); eed= sc->first; - while(eed) { + while (eed) { printf(" ed %x %x %x\n",eed,eed->v1,eed->v2); eed= eed->next; } @@ -627,66 +630,67 @@ static int scanfill(PolyFill *pf) /* STEP 2: FILL LOOP */ - if(pf->f==0) twoconnected= 1; + if (pf->f==0) twoconnected= 1; /* (temporal) security: never much more faces than vertices */ totface= 0; maxface= 2*verts; /* 2*verts: based at a filled circle within a triangle */ sc= scdata; - for(a=0;a<verts;a++) { + for (a=0;a<verts;a++) { /* printf("VERTEX %d %x\n",a,sc->v1); */ ed1= sc->first; - while(ed1) { /* set connectflags */ + while (ed1) { /* set connectflags */ nexted= ed1->next; - if(ed1->v1->h==1 || ed1->v2->h==1) { + if (ed1->v1->h==1 || ed1->v2->h==1) { BLI_remlink((ListBase *)&(sc->first),ed1); BLI_addtail(&filledgebase,ed1); - if(ed1->v1->h>1) ed1->v1->h--; - if(ed1->v2->h>1) ed1->v2->h--; + if (ed1->v1->h>1) ed1->v1->h--; + if (ed1->v2->h>1) ed1->v2->h--; } else ed1->v2->f= 1; ed1= nexted; } - while(sc->first) { /* for as long there are edges */ + while (sc->first) { /* for as long there are edges */ ed1= sc->first; ed2= ed1->next; /* commented out... the ESC here delivers corrupted memory (and doesnt work during grab) */ /* if(callLocalInterruptCallBack()) break; */ - if(totface>maxface) { + if (totface>maxface) { /* printf("Fill error: endless loop. Escaped at vert %d, tot: %d.\n", a, verts); */ a= verts; break; } - if(ed2==0) { + if (ed2==0) { sc->first=sc->last= 0; /* printf("just 1 edge to vert\n"); */ BLI_addtail(&filledgebase,ed1); ed1->v2->f= 0; ed1->v1->h--; ed1->v2->h--; - } else { + } + else { /* test rest of vertices */ v1= ed1->v2; v2= ed1->v1; v3= ed2->v2; /* this happens with a serial of overlapping edges */ - if(v1==v2 || v2==v3) break; + if (v1==v2 || v2==v3) break; /* printf("test verts %x %x %x\n",v1,v2,v3); */ miny = ( (v1->co[coy])<(v3->co[coy]) ? (v1->co[coy]) : (v3->co[coy]) ); /* miny= MIN2(v1->co[coy],v3->co[coy]); */ sc1= sc+1; test= 0; - for(b=a+1;b<verts;b++) { - if(sc1->v1->f==0) { - if(sc1->v1->co[coy] <= miny) break; + for (b=a+1;b<verts;b++) { + if (sc1->v1->f==0) { + if (sc1->v1->co[coy] <= miny) break; - if(testedgeside(v1->co,v2->co,sc1->v1->co)) - if(testedgeside(v2->co,v3->co,sc1->v1->co)) - if(testedgeside(v3->co,v1->co,sc1->v1->co)) { + if (testedgeside(v1->co,v2->co,sc1->v1->co)) + if (testedgeside(v2->co,v3->co,sc1->v1->co)) + if (testedgeside(v3->co,v1->co,sc1->v1->co)) { /* point in triangle */ test= 1; @@ -695,7 +699,7 @@ static int scanfill(PolyFill *pf) } sc1++; } - if(test) { + if (test) { /* make new edge, and start over */ /* printf("add new edge %x %x and start again\n",v2,sc1->v1); */ @@ -718,7 +722,7 @@ static int scanfill(PolyFill *pf) ed1->v1->h--; ed1->v2->h--; /* ed2 can be removed when it's a boundary edge */ - if((ed2->f == 0 && twoconnected) || (ed2->f == FILLBOUNDARY)) { + if ((ed2->f == 0 && twoconnected) || (ed2->f == FILLBOUNDARY)) { BLI_remlink((ListBase *)&(sc->first),ed2); BLI_addtail(&filledgebase,ed2); ed2->v2->f= 0; @@ -736,14 +740,14 @@ static int scanfill(PolyFill *pf) /* printf("add new edge %x %x\n",v1,v3); */ sc1= addedgetoscanlist(ed3, verts); - if(sc1) { /* ed3 already exists: remove if a boundary */ + if (sc1) { /* ed3 already exists: remove if a boundary */ /* printf("Edge exists\n"); */ ed3->v1->h--; ed3->v2->h--; ed3= sc1->first; - while(ed3) { - if( (ed3->v1==v1 && ed3->v2==v3) || (ed3->v1==v3 && ed3->v2==v1) ) { + while (ed3) { + if ( (ed3->v1==v1 && ed3->v2==v3) || (ed3->v1==v3 && ed3->v2==v1) ) { if (twoconnected || ed3->f==FILLBOUNDARY) { BLI_remlink((ListBase *)&(sc1->first),ed3); BLI_addtail(&filledgebase,ed3); @@ -760,13 +764,13 @@ static int scanfill(PolyFill *pf) } /* test for loose edges */ ed1= sc->first; - while(ed1) { + while (ed1) { nexted= ed1->next; - if(ed1->v1->h<2 || ed1->v2->h<2) { + if (ed1->v1->h<2 || ed1->v2->h<2) { BLI_remlink((ListBase *)&(sc->first),ed1); BLI_addtail(&filledgebase,ed1); - if(ed1->v1->h>1) ed1->v1->h--; - if(ed1->v2->h>1) ed1->v2->h--; + if (ed1->v1->h>1) ed1->v1->h--; + if (ed1->v2->h>1) ed1->v2->h--; } ed1= nexted; @@ -809,7 +813,7 @@ int BLI_edgefill(short mat_nr) /* reset variables */ eve= fillvertbase.first; a = 0; - while(eve) { + while (eve) { eve->f= 0; eve->poly_nr= 0; eve->h= 0; @@ -822,7 +826,8 @@ int BLI_edgefill(short mat_nr) addfillface(eve, eve->next, eve->next->next); return 1; - } else if (a == 4 && (mat_nr & 2)) { + } + else if (a == 4 && (mat_nr & 2)) { float vec1[3], vec2[3]; eve = fillvertbase.first; @@ -835,11 +840,13 @@ int BLI_edgefill(short mat_nr) if (dot_v3v3(vec1, vec1) < dot_v3v3(vec2, vec2)) { addfillface(eve, eve->next, eve->next->next); addfillface(eve->next->next, eve->next->next->next, eve); - } else{ + } + else { addfillface(eve->next, eve->next->next, eve->next->next->next); addfillface(eve->next->next->next, eve, eve->next); } - } else { + } + else { addfillface(eve, eve->next, eve->next->next); addfillface(eve->next->next, eve->next->next->next, eve); } @@ -849,7 +856,7 @@ int BLI_edgefill(short mat_nr) /* first test vertices if they are in edges */ /* including resetting of flags */ eed= filledgebase.first; - while(eed) { + while (eed) { eed->poly_nr= 0; eed->v1->f= 1; eed->v2->f= 1; @@ -858,15 +865,15 @@ int BLI_edgefill(short mat_nr) } eve= fillvertbase.first; - while(eve) { - if(eve->f & 1) { + while (eve) { + if (eve->f & 1) { ok=1; break; } eve= eve->next; } - if(ok==0) return 0; + if (ok==0) return 0; /* NEW NEW! define projection: with 'best' normal */ /* just use the first three different vertices */ @@ -880,31 +887,31 @@ int BLI_edgefill(short mat_nr) eve= fillvertbase.first; limit = 1e-8f; - while(eve) { - if(v2) { - if(!compare_v3v3(v2, eve->co, COMPLIMIT)) { + while (eve) { + if (v2) { + if (!compare_v3v3(v2, eve->co, COMPLIMIT)) { float inner = angle_v3v3v3(v1, v2, eve->co); inner = MIN2(fabsf(inner), fabsf(M_PI - inner)); - if(inner > limit) { + if (inner > limit) { limit = inner; len= normal_tri_v3(norm, v1, v2, eve->co); } } } - else if(!compare_v3v3(v1, eve->co, COMPLIMIT)) + else if (!compare_v3v3(v1, eve->co, COMPLIMIT)) v2= eve->co; eve= eve->next; } - if(len==0.0f) return 0; /* no fill possible */ + if (len==0.0f) return 0; /* no fill possible */ axis_dominant_v3(&cox, &coy, norm); /* STEP 1: COUNT POLYS */ eve= fillvertbase.first; - while(eve) { + while (eve) { /* get first vertex with no poly number */ if (eve->poly_nr==0) { poly++; @@ -912,14 +919,14 @@ int BLI_edgefill(short mat_nr) ok= 1; eve->poly_nr = poly; - while(ok) { + while (ok) { ok= 0; toggle++; - if(toggle & 1) eed= filledgebase.first; + if (toggle & 1) eed= filledgebase.first; else eed= filledgebase.last; - while(eed) { + while (eed) { if (eed->v1->poly_nr == 0 && eed->v2->poly_nr == poly) { eed->v1->poly_nr = poly; eed->poly_nr= poly; @@ -936,7 +943,7 @@ int BLI_edgefill(short mat_nr) ok= 1; } } - if(toggle & 1) eed= eed->next; + if (toggle & 1) eed= eed->next; else eed= eed->prev; } } @@ -947,12 +954,12 @@ int BLI_edgefill(short mat_nr) /* STEP 2: remove loose edges and strings of edges */ eed= filledgebase.first; - while(eed) { - if(eed->v1->h++ >250) break; - if(eed->v2->h++ >250) break; + while (eed) { + if (eed->v1->h++ >250) break; + if (eed->v2->h++ >250) break; eed= eed->next; } - if(eed) { + if (eed) { /* otherwise it's impossible to be sure you can clear vertices */ callLocalErrorCallBack("No vertices with 250 edges allowed!"); return 0; @@ -962,21 +969,21 @@ int BLI_edgefill(short mat_nr) testvertexnearedge(); ok= 1; - while(ok) { + while (ok) { ok= 0; toggle++; - if(toggle & 1) eed= filledgebase.first; + if (toggle & 1) eed= filledgebase.first; else eed= filledgebase.last; - while(eed) { - if(toggle & 1) nexted= eed->next; + while (eed) { + if (toggle & 1) nexted= eed->next; else nexted= eed->prev; - if(eed->v1->h==1) { + if (eed->v1->h==1) { eed->v2->h--; BLI_remlink(&fillvertbase,eed->v1); BLI_remlink(&filledgebase,eed); ok= 1; } - else if(eed->v2->h==1) { + else if (eed->v2->h==1) { eed->v1->h--; BLI_remlink(&fillvertbase,eed->v2); BLI_remlink(&filledgebase,eed); @@ -985,7 +992,7 @@ int BLI_edgefill(short mat_nr) eed= nexted; } } - if(filledgebase.first==0) { + if (filledgebase.first==0) { /* printf("All edges removed\n"); */ return 0; } @@ -1005,20 +1012,20 @@ int BLI_edgefill(short mat_nr) /* STEP 3: MAKE POLYFILL STRUCT */ pflist= (PolyFill *)MEM_callocN(poly*sizeof(PolyFill),"edgefill"); pf= pflist; - for(a=1;a<=poly;a++) { + for (a=1;a<=poly;a++) { pf->nr= a; pf->min[0]=pf->min[1]=pf->min[2]= 1.0e20; pf->max[0]=pf->max[1]=pf->max[2]= -1.0e20; pf++; } eed= filledgebase.first; - while(eed) { + while (eed) { pflist[eed->poly_nr-1].edges++; eed= eed->next; } eve= fillvertbase.first; - while(eve) { + while (eve) { pflist[eve->poly_nr-1].verts++; minp= pflist[eve->poly_nr-1].min; maxp= pflist[eve->poly_nr-1].max; @@ -1027,7 +1034,7 @@ int BLI_edgefill(short mat_nr) minp[coy]= (minp[coy])<(eve->co[coy]) ? (minp[coy]) : (eve->co[coy]); maxp[cox]= (maxp[cox])>(eve->co[cox]) ? (maxp[cox]) : (eve->co[cox]); maxp[coy]= (maxp[coy])>(eve->co[coy]) ? (maxp[coy]) : (eve->co[coy]); - if(eve->h > 2) pflist[eve->poly_nr-1].f = 1; + if (eve->h > 2) pflist[eve->poly_nr-1].f = 1; eve= eve->next; } @@ -1037,7 +1044,7 @@ int BLI_edgefill(short mat_nr) * the edgefill itself has good auto-hole detection) * WATCH IT: ONLY WORKS WITH SORTED POLYS!!! */ - if(poly>1) { + if (poly>1) { short *polycache, *pc; /* so, sort first */ @@ -1045,7 +1052,7 @@ int BLI_edgefill(short mat_nr) #if 0 pf= pflist; - for(a=1;a<=poly;a++) { + for (a=1;a<=poly;a++) { printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f); PRINT2(f, f, pf->min[0], pf->min[1]); pf++; @@ -1054,21 +1061,21 @@ int BLI_edgefill(short mat_nr) polycache= pc= MEM_callocN(sizeof(short)*poly, "polycache"); pf= pflist; - for(a=0; a<poly; a++, pf++) { - for(c=a+1;c<poly;c++) { + for (a=0; a<poly; a++, pf++) { + for (c=a+1;c<poly;c++) { /* if 'a' inside 'c': join (bbox too) * Careful: 'a' can also be inside another poly. */ - if(boundisect(pf, pflist+c)) { + if (boundisect(pf, pflist+c)) { *pc= c; pc++; } /* only for optimize! */ - /* else if(pf->max[cox] < (pflist+c)->min[cox]) break; */ + /* else if (pf->max[cox] < (pflist+c)->min[cox]) break; */ } - while(pc!=polycache) { + while (pc!=polycache) { pc--; mergepolysSimp(pf, pflist+ *pc); } @@ -1079,7 +1086,7 @@ int BLI_edgefill(short mat_nr) #if 0 printf("after merge\n"); pf= pflist; - for(a=1;a<=poly;a++) { + for (a=1;a<=poly;a++) { printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f); pf++; } @@ -1095,8 +1102,8 @@ int BLI_edgefill(short mat_nr) filledgebase.first=filledgebase.last= 0; pf= pflist; - for(a=0;a<poly;a++) { - if(pf->edges>1) { + for (a=0;a<poly;a++) { + if (pf->edges>1) { splitlist(&tempve,&temped,pf->nr); totfaces += scanfill(pf); } |