1
0
Fork 0

tgAccumulator: fix accumulator reduction

Signed-off-by: fly <merspieler@alwaysdata.com>
This commit is contained in:
fly 2023-09-23 17:11:14 +02:00 committed by James Turner
parent cd63cc5df4
commit 3afc4578da

View file

@ -90,13 +90,13 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
all_nodes.add( nodes[i] );
}
unsigned int num_hits = 0;
tgRectangle box1 = subject.GetBoundingBox();
ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Paths clipper_result;
while ( !done && max_hits > 0 ) {
unsigned int num_hits = 0;
ClipperLib::Clipper c;
c.Clear();
@ -104,6 +104,10 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
// clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < accum.size(); i++) {
if (num_hits >= max_hits)
{
break;
}
tgRectangle box2 = BoundingBox_FromClipper( accum[i] );
if ( box2.intersects(box1) )
@ -117,10 +121,7 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
if ( !c.Execute(ClipperLib::ClipType::Difference, clipper_result, ClipperLib::PolyFillType::NonZero, ClipperLib::PolyFillType::NonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE - reducing accumulator" );
max_hits = num_hits-1;
FILE* fp = fopen( "./accumulator_fail.log", "a" );
fprintf( fp, "%s : reduce from %u to %u\n", debugstr.c_str(), num_hits, max_hits );
fclose(fp);
SG_LOG(SG_GENERAL, SG_DEBUG, debugstr << ": reduce from " << num_hits << " to " << max_hits );
} else {
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
@ -236,4 +237,4 @@ void tgAccumulator::ToClipperfiles( const std::string& path, const std::string&
}
}
}
}
}