From d66487c3833b389c523e131a4734bf362c0c7a12 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 5 Nov 2021 14:28:49 +0000 Subject: [PATCH] Make sure RTree bounding box is at least as big as hole. Fixes https://gitlab.com/kicad/code/kicad/issues/9526 --- libs/kimath/include/geometry/shape_index.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libs/kimath/include/geometry/shape_index.h b/libs/kimath/include/geometry/shape_index.h index 83f601216b..9566fc8803 100644 --- a/libs/kimath/include/geometry/shape_index.h +++ b/libs/kimath/include/geometry/shape_index.h @@ -49,6 +49,21 @@ static const SHAPE* shapeFunctor( T aItem ) return aItem->Shape(); } +/** + * Used by #SHAPE_INDEX to get a SHAPE* for a hole from another type. + * + * By default relies on T::GetHole() method, should be specialized if the T object + * doesn't allow that method. + * + * @param aItem generic T object. + * @return a SHAPE* object equivalent to object. + */ +template +static const SHAPE* holeFunctor( T aItem ) +{ + return aItem->Hole(); +} + /** * Used by #SHAPE_INDEX to get the bounding box of a generic T object. * @@ -61,7 +76,12 @@ static const SHAPE* shapeFunctor( T aItem ) template BOX2I boundingBox( T aObject ) { - return shapeFunctor( aObject )->BBox(); + BOX2I bbox = shapeFunctor( aObject )->BBox(); + + if( holeFunctor( aObject ) ) + bbox.Merge( holeFunctor( aObject )->BBox() ); + + return bbox; } /**