From f64abcba364b5b9535334792602337d734870840 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 9 Sep 2021 15:35:09 +0100 Subject: [PATCH] Restore BBoxCache usage for zone fill performance. --- libs/kimath/include/geometry/shape.h | 2 ++ libs/kimath/include/geometry/shape_line_chain.h | 4 ++-- libs/kimath/src/geometry/shape_line_chain.cpp | 6 ++---- libs/kimath/src/geometry/shape_poly_set.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/kimath/include/geometry/shape.h b/libs/kimath/include/geometry/shape.h index 7a65d85449..1768ec5587 100644 --- a/libs/kimath/include/geometry/shape.h +++ b/libs/kimath/include/geometry/shape.h @@ -308,6 +308,8 @@ public: virtual size_t GetPointCount() const = 0; virtual size_t GetSegmentCount() const = 0; virtual bool IsClosed() const = 0; + + virtual BOX2I* GetCachedBBox() const { return nullptr; } }; #endif // __SHAPE_H diff --git a/libs/kimath/include/geometry/shape_line_chain.h b/libs/kimath/include/geometry/shape_line_chain.h index 117e2fa108..3d054fd22a 100644 --- a/libs/kimath/include/geometry/shape_line_chain.h +++ b/libs/kimath/include/geometry/shape_line_chain.h @@ -413,9 +413,9 @@ public: m_bbox.Inflate( m_width ); } - const BOX2I BBoxFromCache() const + BOX2I* GetCachedBBox() const override { - return m_bbox; + return &m_bbox; } /** diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index 1098c83ff3..a7b0eedb49 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -1323,10 +1323,8 @@ bool SHAPE_LINE_CHAIN_BASE::PointInside( const VECTOR2I& aPt, int aAccuracy, * Don't check the bounding box unless it's cached. Building it is about the same speed as * the rigorous test below and so just slows things down by doing potentially two tests. */ - //if( aUseBBoxCache && !m_bbox.Contains( aPt ) ) - //return false; - - // fixme: bbox cache... + if( aUseBBoxCache && GetCachedBBox() && !GetCachedBBox()->Contains( aPt ) ) + return false; if( !IsClosed() || GetPointCount() < 3 ) return false; diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index f157b31f46..0958b06157 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -1402,9 +1402,9 @@ const BOX2I SHAPE_POLY_SET::BBoxFromCaches() const for( unsigned i = 0; i < m_polys.size(); i++ ) { if( i == 0 ) - bb = m_polys[i][0].BBoxFromCache(); + bb = *m_polys[i][0].GetCachedBBox(); else - bb.Merge( m_polys[i][0].BBoxFromCache() ); + bb.Merge( *m_polys[i][0].GetCachedBBox() ); } return bb;