Skip to content

Commit 92c5b2f

Browse files
authored
Merge pull request #3394 from roystgnr/refinement_fix
Poly2Tri refinement API fix
2 parents 9afd7e6 + cba8d9a commit 92c5b2f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/mesh/poly2tri_triangulator.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void Poly2TriTriangulator::triangulate()
209209
{
210210
this->triangulate_current_points();
211211
}
212-
while (!this->insert_refinement_points());
212+
while (this->insert_refinement_points());
213213

214214
// Okay, we really do need to support boundary ids soon, but we
215215
// don't yet
@@ -1145,7 +1145,7 @@ bool Poly2TriTriangulator::insert_refinement_points()
11451145
mesh.add_elem(std::move(new_elem_pair.second));
11461146

11471147
// Did we add anything?
1148-
return new_elems.empty();
1148+
return !new_elems.empty();
11491149
}
11501150

11511151

tests/mesh/mesh_triangulation.C

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public:
4545
CPPUNIT_TEST( testPoly2TriEdgesRefined );
4646
CPPUNIT_TEST( testPoly2TriSegments );
4747
CPPUNIT_TEST( testPoly2TriRefined );
48+
CPPUNIT_TEST( testPoly2TriNonRefined );
4849
CPPUNIT_TEST( testPoly2TriExtraRefined );
4950
CPPUNIT_TEST( testPoly2TriHolesRefined );
5051
CPPUNIT_TEST( testPoly2TriHolesInterpRefined );
@@ -901,7 +902,11 @@ public:
901902

902903
triangulator.triangulate();
903904

904-
CPPUNIT_ASSERT(mesh.n_elem() > n_original_elem);
905+
// If refinement should have increased our element count, check it
906+
if (desired_area || area_func)
907+
CPPUNIT_ASSERT_LESS(mesh.n_elem(), n_original_elem); // n_elem+++
908+
else
909+
CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), n_original_elem);
905910

906911
Real area = 0;
907912
for (const auto & elem : mesh.active_local_element_ptr_range())
@@ -940,6 +945,17 @@ public:
940945
testPoly2TriRefinementBase(mesh, nullptr, 1.5, 15);
941946
}
942947

948+
void testPoly2TriNonRefined()
949+
{
950+
LOG_UNIT_TEST;
951+
952+
Mesh mesh(*TestCommWorld);
953+
testPoly2TriTrapMesh(mesh);
954+
// Make sure we see 0 as "don't refine", not "infinitely refine"
955+
testPoly2TriRefinementBase(mesh, nullptr, 1.5, 2, 0);
956+
}
957+
958+
943959
void testPoly2TriExtraRefined()
944960
{
945961
LOG_UNIT_TEST;

0 commit comments

Comments
 (0)