csg2d - fix bug in getNonIntersectionVertex()

If a loop has no non-intersecting vertex, a new one is inserted
-> set all vertex properties correctly (info, spline)
This commit is contained in:
Matthias Hochsteger 2020-11-03 18:42:04 +01:00
parent 45059fa7af
commit 8b14f399c1
2 changed files with 38 additions and 21 deletions

View File

@ -1565,6 +1565,39 @@ Solid2d ClipSolids ( Solid2d && s1, Solid2d && s2, char op)
return std::move(res);
}
Vertex* Loop :: getNonIntersectionVertex()
{
for (Vertex* v : Vertices(ALL))
if (!v->is_intersection)
return(v);
// no non-intersection vertex found -> generate and return temporary vertex
for (Vertex* v : Vertices(ALL))
// make sure that edge from V to V->next is not collinear with other polygon
if ( (v->next->neighbour != v->neighbour->prev) && (v->next->neighbour != v->neighbour->next) )
{
// add edge midpoint as temporary vertex
if(v->spline)
{
auto p = v->spline->GetPoint(0.5);
auto s = *v->spline;
v->spline = Split(s, 0, 0.5);
auto vnew = v->Insert(p);
vnew->info = v->info;
vnew->spline = Split(s, 0.5, 1.0);
return vnew;
}
else
{
auto p = Center(*v, *v->next);
auto vnew = v->Insert(p);
vnew->info = v->info;
return vnew;
}
}
return(NULL);
}
bool Loop :: IsInside( Point<2> r ) const
{
int w = 0;

View File

@ -29,10 +29,10 @@ enum IntersectionType
T_INTERSECTION_Q,
T_INTERSECTION_P,
V_INTERSECTION,
X_OVERLAP,
T_OVERLAP_Q,
T_OVERLAP_P,
V_OVERLAP
X_OVERLAP, // Q0 -- P1 -- Q1 -- P0 (different direction)
T_OVERLAP_Q, // same direction or P inside Q
T_OVERLAP_P, // same direction or Q inside P
V_OVERLAP // one common point
};
enum IntersectionLabel
@ -588,23 +588,7 @@ struct Loop
//
// return and insert a non-intersection vertex
//
Vertex* getNonIntersectionVertex()
{
for (Vertex* v : Vertices(ALL))
if (!v->is_intersection)
return(v);
// no non-intersection vertex found -> generate and return temporary vertex
for (Vertex* v : Vertices(ALL))
// make sure that edge from V to V->next is not collinear with other polygon
if ( (v->next->neighbour != v->neighbour->prev) && (v->next->neighbour != v->neighbour->next) )
{
// add edge midpoint as temporary vertex
auto p = Center(*v, *v->next);
return v->Insert(p);
}
return(NULL);
}
Vertex* getNonIntersectionVertex();
void SetBC(string bc)
{