Skip to content

Commit 6e32ef5

Browse files
Do not allow creation of flat triangles in edge enforcement. Modify threshold for float comparison that could create false positive. Fix index bug
1 parent d9098ad commit 6e32ef5

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/mmg2d/enforcement_2d.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ int MMG2D_bdryenforcement(MMG5_pMesh mesh,MMG5_pSol sol) {
194194
while ( l++ < lon ) {
195195
pt = &mesh->tria[k];
196196
if ( pt->base == mesh->base+1 ) break;
197-
k = list[(++ii)%lon] / 3;
197+
ii = (ii+1)%lon;
198+
k = list[ii] / 3;
198199
}
199200

200201
assert ( l <= lon );
@@ -247,7 +248,7 @@ int MMG2D_bdryenforcement(MMG5_pMesh mesh,MMG5_pSol sol) {
247248
}
248249
break;
249250
}
250-
ii++;
251+
ii = (ii+1)%lon;
251252
}
252253
}
253254
}

src/mmg2d/locate_2d.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,21 @@ int MMG2D_cutEdgeTriangle(MMG5_pMesh mesh,MMG5_int k,MMG5_int ia,MMG5_int ib) {
167167
prod3 = area3*area1;
168168

169169
/* Both edges p2p3 and p1p3 corresponding to prod2 and prod3 are cut by edge ia,ib */
170-
if ( prod1 > 0 && ((prod2 < 0 || prod3 < 0))) {
170+
if ( prod1 > MMG2D_EPSD && ((prod2 < -MMG2D_EPSD || prod3 < -MMG2D_EPSD ))) {
171171
if ( (iare = MMG2D_cutEdge(mesh,pt,ppa,ppb)) ) {
172172
return iare;
173173
}
174174
}
175175

176176
/* Both edges corresponding to prod1 and prod3 are cut by edge ia,ib */
177-
if ( prod2 > 0 && ((prod1 < 0 || prod3 < 0))) {
177+
if ( prod2 > MMG2D_EPSD && ((prod1 < -MMG2D_EPSD || prod3 < -MMG2D_EPSD ))) {
178178
if ( (iare = MMG2D_cutEdge(mesh,pt,ppa,ppb)) ) {
179179
return iare;
180180
}
181181
}
182182

183183
/* Both edges corresponding to prod1 and prod2 are cut by edge ia,ib */
184-
if ( prod3 > 0 && ((prod2 < 0 || prod1 < 0))) {
184+
if ( prod3 > MMG2D_EPSD && ((prod2 < -MMG2D_EPSD || prod1 < -MMG2D_EPSD ))) {
185185
if ( (iare = MMG2D_cutEdge(mesh,pt,ppa,ppb)) ) {
186186
return iare;
187187
}
@@ -191,7 +191,7 @@ int MMG2D_cutEdgeTriangle(MMG5_pMesh mesh,MMG5_int k,MMG5_int ia,MMG5_int ib) {
191191
for(i=0; i<3; i++){
192192
if ( pt->v[i] == ia || ibreak ) {
193193
/* One vertex is ia, and the opposite edge is frankly crossed */
194-
if ( (prod1 < 0) || (prod2 < 0) || (prod3 < 0) ) {
194+
if ( (prod1 < -MMG2D_EPSD) || (prod2 < -MMG2D_EPSD) || (prod3 < -MMG2D_EPSD) ) {
195195
if ( (iare = MMG2D_cutEdge(mesh,pt,ppa,ppb)) ) {
196196
return iare;
197197
}

src/mmg2d/swapar_2d.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ int MMG2D_swapdelone(MMG5_pMesh mesh,MMG5_pSol sol,MMG5_int k,int8_t i,double cr
7878
arean2 = MMG2D_quickarea(mesh->point[pt0->v[0]].c,mesh->point[pt0->v[1]].c,mesh->point[pt0->v[2]].c);
7979
if ( cal2 > crit ) return 0;
8080

81+
/* Avoid creation of a flat triangle*/
82+
if (fabs(arean1) < MMG2D_EPSD || fabs(arean2) < MMG2D_EPSD) {
83+
return 0;
84+
}
85+
8186
if ( arean1 < 0.0 || arean2 < 0.0 || fabs((area1+area2)-(arean1+arean2)) > MMG2D_EPSD ) {
8287
if(mesh->info.ddebug) printf(" ## Warning: non convex configuration\n");
8388
return 0;

0 commit comments

Comments
 (0)