From 3afc4578da2062a5a67914a00c34bd8cd626e95c Mon Sep 17 00:00:00 2001 From: fly <merspieler@alwaysdata.com> Date: Sat, 23 Sep 2023 17:11:14 +0200 Subject: [PATCH] tgAccumulator: fix accumulator reduction Signed-off-by: fly <merspieler@alwaysdata.com> --- src/Lib/terragear/tg_accumulator.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Lib/terragear/tg_accumulator.cxx b/src/Lib/terragear/tg_accumulator.cxx index 7a4adb1e..c28319d7 100644 --- a/src/Lib/terragear/tg_accumulator.cxx +++ b/src/Lib/terragear/tg_accumulator.cxx @@ -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& } } } -} \ No newline at end of file +}