walk_to_next_3: reformat to indentation by 2 space

This commit is contained in:
Laurent Rineau 2023-06-16 18:10:19 +02:00
parent dcfd783953
commit f193744e66
1 changed files with 286 additions and 307 deletions

View File

@ -334,15 +334,12 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
const Simplex& cur) const const Simplex& cur) const
{ {
const auto cur_cell = cur.cell; const auto cur_cell = cur.cell;
std::array<const Point*, 4> vert std::array<const Point*, 4> vert = {&(cur_cell->vertex(0)->point()), &(cur_cell->vertex(1)->point()),
= {&(cur_cell->vertex(0)->point()), &(cur_cell->vertex(2)->point()), &(cur_cell->vertex(3)->point())};
&(cur_cell->vertex(1)->point()),
&(cur_cell->vertex(2)->point()),
&(cur_cell->vertex(3)->point()) };
int inside=0,outside=0,regular_case=0,degenerate=0; int inside = 0, outside = 0, regular_case = 0, degenerate = 0;
if (cur.lt == Tr::FACET && prev.cell != Cell_handle()) { if(cur.lt == Tr::FACET && prev.cell != Cell_handle()) {
// [source, target] entered the cell `cur` via a facet. // [source, target] entered the cell `cur` via a facet.
// Note that, if prev.cell == Cell_handle(), that means `source` is *on* // Note that, if prev.cell == Cell_handle(), that means `source` is *on*
// the facet, and the block of this `if` cannot be applied. // the facet, and the block of this `if` cannot be applied.
@ -351,17 +348,16 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
auto case_target_is_inside_cur_cell = [&](int case_nb) { auto case_target_is_inside_cur_cell = [&](int case_nb) {
inside = case_nb; inside = case_nb;
prev_after_walk = { cur_cell, Tr::CELL, -1, -1 }; prev_after_walk = {cur_cell, Tr::CELL, -1, -1};
cur_after_walk = { {}, Tr::CELL, -1, -1 }; cur_after_walk = {{}, Tr::CELL, -1, -1};
}; };
auto case_segment_exits_cur_cell_by = [&](int facet_nb, auto case_segment_exits_cur_cell_by = [&](int facet_nb, Cell_handle nnext = {}) {
Cell_handle nnext = {}) {
if(nnext == Cell_handle{}) { if(nnext == Cell_handle{}) {
nnext = cur_cell->neighbor(facet_nb); nnext = cur_cell->neighbor(facet_nb);
} }
outside = facet_nb; outside = facet_nb;
prev_after_walk = { cur_cell, Tr::FACET, facet_nb, -1 }; prev_after_walk = {cur_cell, Tr::FACET, facet_nb, -1};
cur_after_walk = { nnext, Tr::FACET, nnext->index(cur_cell), -1 }; cur_after_walk = {nnext, Tr::FACET, nnext->index(cur_cell), -1};
}; };
regular_case = 1; regular_case = 1;
const int i = cur.li; const int i = cur.li;
@ -369,66 +365,62 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
const int j1 = Tr::vertex_triple_index(i, 1); const int j1 = Tr::vertex_triple_index(i, 1);
const int j2 = Tr::vertex_triple_index(i, 2); const int j2 = Tr::vertex_triple_index(i, 2);
Orientation o0 = _tr->orientation(_source, *vert[i], *vert[j0], _target); Orientation o0 = _tr->orientation(_source, *vert[i], *vert[j0], _target);
if (o0 == POSITIVE) { // o0 > 0 if(o0 == POSITIVE) { // o0 > 0
Orientation o1 = _tr->orientation(_source, *vert[i], *vert[j1], _target); Orientation o1 = _tr->orientation(_source, *vert[i], *vert[j1], _target);
if (o1 != POSITIVE) { // o1 <= 0 if(o1 != POSITIVE) { // o1 <= 0
Orientation oi01 = _tr->orientation(*vert[i], *vert[j0], *vert[j1], _target); Orientation oi01 = _tr->orientation(*vert[i], *vert[j0], *vert[j1], _target);
if (oi01 == POSITIVE) { if(oi01 == POSITIVE) {
case_segment_exits_cur_cell_by(j2); case_segment_exits_cur_cell_by(j2);
if (o1 == ZERO) degenerate = 1; //EDGE i j1 if(o1 == ZERO)
} degenerate = 1; // EDGE i j1
else { // o0 > 0, o1 <= 0, oi01 <= 0 } else { // o0 > 0, o1 <= 0, oi01 <= 0
case_target_is_inside_cur_cell(1); case_target_is_inside_cur_cell(1);
if(oi01 == ZERO) { // on FACET j2 (i, j0, j1) if(oi01 == ZERO) { // on FACET j2 (i, j0, j1)
degenerate = 1; degenerate = 1;
} // end oi01 == ZERO } // end oi01 == ZERO
} }
} // end o1 <= 0 } // end o1 <= 0
else { // o1 > 0 else
{ // o1 > 0
Orientation oi12 = _tr->orientation(*vert[i], *vert[j1], *vert[j2], _target); Orientation oi12 = _tr->orientation(*vert[i], *vert[j1], *vert[j2], _target);
if ( oi12 == POSITIVE) { if(oi12 == POSITIVE) {
case_segment_exits_cur_cell_by(j0); case_segment_exits_cur_cell_by(j0);
} } else { // o0 > 0, o1 > 0, oi12 <= 0
else { // o0 > 0, o1 > 0, oi12 <= 0
case_target_is_inside_cur_cell(2); case_target_is_inside_cur_cell(2);
if( oi12 == ZERO) { // on FACET j0 (i, j1, j2) if(oi12 == ZERO) { // on FACET j0 (i, j1, j2)
degenerate = 1; degenerate = 1;
} // end oi12 == ZERO } // end oi12 == ZERO
} }
} }
} // end o0 > 0 } // end o0 > 0
else if (o0 == ZERO) { else if(o0 == ZERO)
{
// target is on plane (source, vert[i], vert[j0]) // target is on plane (source, vert[i], vert[j0])
Orientation o1 = _tr->orientation(_source, *vert[i], *vert[j1], _target); Orientation o1 = _tr->orientation(_source, *vert[i], *vert[j1], _target);
if (o1 == NEGATIVE) { if(o1 == NEGATIVE) {
Orientation oi12 = _tr->orientation(*vert[i], *vert[j0], *vert[j1], _target); Orientation oi12 = _tr->orientation(*vert[i], *vert[j0], *vert[j1], _target);
if (oi12 == POSITIVE) { if(oi12 == POSITIVE) {
degenerate = 2; degenerate = 2;
case_segment_exits_cur_cell_by(44, cur_cell->neighbor(j2)); //EDGE i j0 case_segment_exits_cur_cell_by(44, cur_cell->neighbor(j2)); // EDGE i j0
} } else {
else {
case_target_is_inside_cur_cell(3); case_target_is_inside_cur_cell(3);
if(oi12 == ZERO) { // target is *on* EDGE i j0 if(oi12 == ZERO) { // target is *on* EDGE i j0
degenerate = 1; degenerate = 1;
} }
} }
} } else if(o1 == ZERO) {
else if (o1 == ZERO) {
// o0 == o1 == 0 -> target is on line source-vert[i] // o0 == o1 == 0 -> target is on line source-vert[i]
if (_tr->orientation(*vert[i], *vert[j0], *vert[j2], _target) == POSITIVE) if(_tr->orientation(*vert[i], *vert[j0], *vert[j2], _target) == POSITIVE)
case_target_is_inside_cur_cell(55); case_target_is_inside_cur_cell(55);
else
{
degenerate = 3;
case_segment_exits_cur_cell_by(5, cur_cell->neighbor(j2)); //VERTEX i
}
}
else { // o0 == 0, o1 > 0
Orientation oi12 = _tr->orientation(*vert[i], *vert[j1], *vert[j2], _target);
if (oi12 == POSITIVE) {
case_segment_exits_cur_cell_by(j0);
}
else { else {
degenerate = 3;
case_segment_exits_cur_cell_by(5, cur_cell->neighbor(j2)); // VERTEX i
}
} else { // o0 == 0, o1 > 0
Orientation oi12 = _tr->orientation(*vert[i], *vert[j1], *vert[j2], _target);
if(oi12 == POSITIVE) {
case_segment_exits_cur_cell_by(j0);
} else {
case_target_is_inside_cur_cell(4); case_target_is_inside_cur_cell(4);
if(oi12 == ZERO) { // on FACET j0 (i, j1, j2) if(oi12 == ZERO) { // on FACET j0 (i, j1, j2)
degenerate = 1; degenerate = 1;
@ -436,28 +428,27 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
} }
} }
} // end o0 == 0 } // end o0 == 0
else { // o0 < 0 else
{ // o0 < 0
Orientation o2 = _tr->orientation(_source, *vert[i], *vert[j2], _target); Orientation o2 = _tr->orientation(_source, *vert[i], *vert[j2], _target);
if (o2 != NEGATIVE) { if(o2 != NEGATIVE) {
// o2 >= 0 // o2 >= 0
Orientation oi20 = _tr->orientation(*vert[i], *vert[j2], *vert[j0], _target); Orientation oi20 = _tr->orientation(*vert[i], *vert[j2], *vert[j0], _target);
if ( oi20 == POSITIVE) { if(oi20 == POSITIVE) {
case_segment_exits_cur_cell_by(j1); case_segment_exits_cur_cell_by(j1);
if (o2 == ZERO) degenerate = 4; // EDGE i j2 if(o2 == ZERO)
} degenerate = 4; // EDGE i j2
else { } else {
case_target_is_inside_cur_cell(5); case_target_is_inside_cur_cell(5);
if(oi20 == ZERO) { // on FACET j1 (i, j2, j0) if(oi20 == ZERO) { // on FACET j1 (i, j2, j0)
degenerate = 1; degenerate = 1;
} }
} }
} } else {
else {
Orientation oi12 = _tr->orientation(*vert[i], *vert[j1], *vert[j2], _target); Orientation oi12 = _tr->orientation(*vert[i], *vert[j1], *vert[j2], _target);
if (oi12 == POSITIVE) { if(oi12 == POSITIVE) {
case_segment_exits_cur_cell_by(j0); case_segment_exits_cur_cell_by(j0);
} } else {
else {
case_target_is_inside_cur_cell(6); case_target_is_inside_cur_cell(6);
if(oi12 == ZERO) { // on FACET j0 (i, j1, j2) if(oi12 == ZERO) { // on FACET j0 (i, j1, j2)
degenerate = 1; degenerate = 1;
@ -466,13 +457,11 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
} }
} }
if (!degenerate) if(!degenerate) {
{ return {prev_after_walk, cur_after_walk};
return { prev_after_walk, cur_after_walk };
} }
} }
// We check in which direction the target lies // We check in which direction the target lies
// by comparing its position relative to the planes through the // by comparing its position relative to the planes through the
// source and the edges of the cell. // source and the edges of the cell.
@ -480,33 +469,32 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
std::array<Orientation, 4> op; std::array<Orientation, 4> op;
int pos = 0; int pos = 0;
// We keep track of which orientations are calculated. // We keep track of which orientations are calculated.
bool calc[6] = { false, false, false, false, false, false }; bool calc[6] = {false, false, false, false, false, false};
if( cur.lt == Tr::VERTEX ) { if(cur.lt == Tr::VERTEX) {
// The three planes through the vertex are set to coplanar. // The three planes through the vertex are set to coplanar.
for( int j = 0; j < 4; ++j ) { for(int j = 0; j < 4; ++j) {
if( cur.li != j ) { if(cur.li != j) {
int ij = edgeIndex( cur.li, j ); int ij = edgeIndex(cur.li, j);
o[ij] = COPLANAR; o[ij] = COPLANAR;
calc[ij] = true; calc[ij] = true;
} }
} }
} } else if(cur.lt == Tr::EDGE) {
else if( cur.lt == Tr::EDGE ) {
// The plane through the edge is set to coplanar. // The plane through the edge is set to coplanar.
int ij = edgeIndex( cur.li, cur.lj ); int ij = edgeIndex(cur.li, cur.lj);
o[ij] = COPLANAR; o[ij] = COPLANAR;
calc[ij] = true; calc[ij] = true;
} }
// For the remembering stochastic walk, we start trying with a random facet. // For the remembering stochastic walk, we start trying with a random facet.
CGAL_triangulation_assertion_code( bool incell = true; ) CGAL_triangulation_assertion_code(bool incell = true;)
for( int li = 0; li < 4; ++li)
for(int li = 0; li < 4; ++li)
{ {
// Skip the previous cell. // Skip the previous cell.
Cell_handle next = cur_cell->neighbor(li); Cell_handle next = cur_cell->neighbor(li);
if( next == prev.cell ) if(next == prev.cell) {
{
op[li] = POSITIVE; op[li] = POSITIVE;
pos += li; pos += li;
continue; continue;
@ -514,48 +502,47 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
const Point* const backup_vert_li = std::exchange(vert[li], &_target); const Point* const backup_vert_li = std::exchange(vert[li], &_target);
// Check if the target is on the opposite side of the supporting plane. // Check if the target is on the opposite side of the supporting plane.
op[li] = _tr->orientation( *vert[0], *vert[1], *vert[2], *vert[3] ); op[li] = _tr->orientation(*vert[0], *vert[1], *vert[2], *vert[3]);
if( op[li] == POSITIVE ) if(op[li] == POSITIVE)
pos += li; pos += li;
if( op[li] != NEGATIVE ) { if(op[li] != NEGATIVE) {
vert[li] = backup_vert_li; vert[li] = backup_vert_li;
continue; continue;
} }
CGAL_triangulation_assertion_code( incell = false; ) CGAL_triangulation_assertion_code(incell = false;)
// Check if the target is inside the 3-wedge with // Check if the target is inside the 3-wedge with
// the source as apex and the facet as an intersection. // the source as apex and the facet as an intersection.
int Or = 0; int Or = 0;
for( int lj = 0; lj < 4; ++lj ) { for(int lj = 0; lj < 4; ++lj) {
if( li == lj ) if(li == lj)
continue; continue;
// We check the orientation of the target compared to the plane // We check the orientation of the target compared to the plane
// Through the source and the edge opposite of ij. // Through the source and the edge opposite of ij.
const int oij = 5 - edgeIndex( li, lj ); const int oij = 5 - edgeIndex(li, lj);
if( !calc[oij] ) { if(!calc[oij]) {
const Point* const backup_vert_lj = std::exchange(vert[lj], &_source); const Point* const backup_vert_lj = std::exchange(vert[lj], &_source);
o[oij] = _tr->orientation( *vert[0], *vert[1], *vert[2], *vert[3] ); o[oij] = _tr->orientation(*vert[0], *vert[1], *vert[2], *vert[3]);
vert[lj] = backup_vert_lj; vert[lj] = backup_vert_lj;
calc[oij] = true; calc[oij] = true;
} }
if(o[oij] == POSITIVE) {
if( o[oij] == POSITIVE ) {
// The target is not inside the pyramid. // The target is not inside the pyramid.
// Invert the planes. // Invert the planes.
for( int j = 0; j < 4; ++j ) { for(int j = 0; j < 4; ++j) {
if( li == j ) continue; if(li == j)
int oij = 5 - edgeIndex( li, j ); continue;
if(calc[oij]) o[oij] = -o[oij]; int oij = 5 - edgeIndex(li, j);
if(calc[oij])
o[oij] = -o[oij];
} }
Or = 0; Or = 0;
break; break;
} } else
else
Or -= o[oij]; Or -= o[oij];
} }
if( Or == 0 ) { if(Or == 0) {
// Either the target is not inside the pyramid, // Either the target is not inside the pyramid,
// or the pyramid is degenerate. // or the pyramid is degenerate.
vert[li] = backup_vert_li; vert[li] = backup_vert_li;
@ -563,29 +550,23 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
} }
// The target is inside the pyramid. // The target is inside the pyramid.
switch( Or ) { switch(Or) {
case 3: { case 3: {
if(regular_case) if(regular_case) {
{ CGAL_triangulation_assertion(li == outside);
CGAL_triangulation_assertion( li==outside ); CGAL_triangulation_assertion(!inside);
CGAL_triangulation_assertion( ! inside );
} }
return { {cur_cell, Tr::FACET, li}, return {{cur_cell, Tr::FACET, li}, {next, Tr::FACET, next->index(cur_cell)}};
{next, Tr::FACET, next->index(cur_cell)} };
} }
case 2: { case 2: {
if(regular_case) if(regular_case)
CGAL_triangulation_assertion(degenerate ); CGAL_triangulation_assertion(degenerate);
for(int j = 0; j < 4; ++j) {
for( int j = 0; j < 4; ++j ) { if(li != j && o[5 - edgeIndex(li, j)] == COPLANAR) {
if( li != j && o[ 5 - edgeIndex(li, j) ] == COPLANAR) { Edge opp = opposite_edge(prev.cell, li, j);
Edge opp = opposite_edge( prev.cell, li, j ); return {
return { {cur_cell, Tr::EDGE, opp.second, opp.third}, {cur_cell, Tr::EDGE, opp.second, opp.third},
{next, Tr::EDGE, {next, Tr::EDGE, next->index(cur_cell->vertex(opp.second)), next->index(cur_cell->vertex(opp.third))}};
next->index(cur_cell->vertex( opp.second )),
next->index(cur_cell->vertex( opp.third ))
}
};
} }
} }
CGAL_unreachable(); CGAL_unreachable();
@ -593,12 +574,10 @@ Triangulation_segment_cell_iterator_3<Tr,Inc>::walk_to_next_3(const Simplex& pre
} }
case 1: case 1:
if(regular_case) if(regular_case)
CGAL_triangulation_assertion(degenerate ); CGAL_triangulation_assertion(degenerate);
for(int j = 0; j < 4; ++j) {
for( int j = 0; j < 4; ++j ) { if(li != j && o[5 - edgeIndex(li, j)] == NEGATIVE) {
if( li != j && o[ 5 - edgeIndex(li, j) ] == NEGATIVE ) { return {{cur_cell, Tr::VERTEX, j}, {next, Tr::VERTEX, next->index(cur_cell->vertex(j))}};
return { {cur_cell, Tr::VERTEX, j},
{next, Tr::VERTEX, next->index(cur_cell->vertex(j))} };
} }
} }
CGAL_unreachable(); CGAL_unreachable();