Use BoxTree::GetFirstIntersecting

This commit is contained in:
Matthias Hochsteger 2019-10-01 12:34:23 +02:00
parent 7ced41e56f
commit 8bfccdf1df

View File

@ -1349,18 +1349,13 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
Line2d l1 (p2d1, p2d2);
double eps = 1e-6;
bool ok = true;
if (searchtree)
{
NgArrayMem<INDEX_2,100> pis;
searchtree -> GetIntersecting (box2d.PMin(), box2d.PMax(), pis);
for (auto i2 : pis)
auto hasIntersection = [&] (auto i2) NETGEN_LAMBDA_INLINE
{
const STLBoundarySeg & seg = boundary_ht[i2];
if (seg.IsSmoothEdge()) continue;
if (!box2d.Intersect (seg.BoundingBox())) continue;
if (seg.IsSmoothEdge()) return false;
if (!box2d.Intersect (seg.BoundingBox())) return false;
const Point<2> & sp1 = seg.P2D1();
const Point<2> & sp2 = seg.P2D2();
@ -1375,44 +1370,30 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
bool on2 = (lam2 > -eps) && (lam2 < 1 + eps);
if(!err && ((on1 && in2) || (on2 && in1)))
{
ok = false;
break;
}
}
}
return true;
return false;
};
if (searchtree)
{
bool has_intersection = false;
searchtree -> GetFirstIntersecting (box2d.PMin(), box2d.PMax(),
[&] (auto i2) NETGEN_LAMBDA_INLINE
{
has_intersection = hasIntersection(i2);
return has_intersection;
});
return !has_intersection;
}
else
{
for(auto [i2, seg] : boundary_ht)
{
if (seg.IsSmoothEdge()) continue;
if (!box2d.Intersect (seg.BoundingBox())) continue;
const Point<2> & sp1 = seg.P2D1();
const Point<2> & sp2 = seg.P2D2();
Line2d l2 (sp1, sp2);
double lam1, lam2;
int err = CrossPointBarycentric (l1, l2, lam1, lam2);
bool in1 = (lam1 > eps) && (lam1 < 1-eps);
bool on1 = (lam1 > -eps) && (lam1 < 1 + eps);
bool in2 = (lam2 > eps) && (lam2 < 1-eps);
bool on2 = (lam2 > -eps) && (lam2 < 1 + eps);
if(!err && ((on1 && in2) || (on2 && in1)))
{
ok = false;
break;
if(hasIntersection(i2))
return false;
return true;
}
}
}
return ok;
}
STLDoctorParams :: STLDoctorParams()