handle cases when plane contains an edge

This commit is contained in:
Sébastien Loriot 2021-02-10 10:29:02 +01:00
parent 38142dc101
commit 231e9f1b93
2 changed files with 19 additions and 15 deletions

View File

@ -97,6 +97,19 @@ intersection(
std::vector<std::array<int,2>> neighbor_ids(14, {-1,-1});
auto add_neighbor = [&neighbor_ids](int i, int j)
{
if (neighbor_ids[i][0] == -1 ) {
neighbor_ids[i][0] = j;
}
else {
if (neighbor_ids[i][0]!=j && neighbor_ids[i][1]==-1)
{
neighbor_ids[i][1] = j;
}
}
};
int start_id = -1;
int solo_id = -1;
// for each face of the bbox, we look for intersection of the plane with its edges
@ -155,18 +168,8 @@ intersection(
case 2:
{
if (start_id == -1) start_id = ids[0];
if (neighbor_ids[ids[0]][0] == -1) {
neighbor_ids[ids[0]][0] = ids[1];
}
else {
neighbor_ids[ids[0]][1] = ids[1];
}
if (neighbor_ids[ids[1]][0] == -1) {
neighbor_ids[ids[1]][0] = ids[0];
}
else {
neighbor_ids[ids[1]][1] = ids[0];
}
add_neighbor(ids[0], ids[1]);
add_neighbor(ids[1], ids[0]);
break;
}
case 1:

View File

@ -907,7 +907,7 @@ struct Test {
//edge
check_intersection (cub, Pl(P(1,1,1), P(1,2,1), P(1.5,0,0)),
S(P(1,2,1), P(1,1,1)));
S(P(1,1,1), P(1,2,1)));
//face
@ -924,6 +924,7 @@ struct Test {
assert(p.x() == 1);
}
res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2)));
poly = boost::get<std::vector<P> >(&*res);
assert(poly != nullptr);
assert(poly->size() == 4);
@ -940,8 +941,8 @@ struct Test {
check_intersection (cub, Pl(P(2, 1.66, 2),
P(1.66,2,2),
P(2,2,1.66)),
Tr(P(2, 2, 1.66),
P(1.66,2,2),
Tr(P(1.66,2,2),
P(2, 2, 1.66),
P(2,1.66,2)));
//other edge