improving empty handling in tools::Rectangle

Noel Grandin noelgrandin at
Tue May 7 09:30:40 UTC 2019


For background: tools::Rectangle currently has magic values for it's bottom and right fields that indicate that 
width/height is "empty".

Unfortunately, this leads to two problems
(1) the magic value is -32767, and sometimes that is a valid input value for a rectangle. Which means that rectangles 
can suddenly become "empty".
(2) lots of code processes empty rectangles and just calls GetRight()/GetBottom(), which returns the magic -32767 value, 
does some calculations on that value, and just continues happily.

All of which means that we pass around bogus data.

To improve this, I propose to do 3 things
(1) split the empty flags into their own bool values.
(2) make more of the tools::Rectangle methods do reasonable things when the empty flag is set.
(3) assert if code access Right or Bottom on an empty rectangle.

There are currently two gerrit changes related to this:
Does a first piece, improving the conversion from tools::Rectangle to basegfx::B2DRectangle/B2IRectangle,
so that empty translates reasonably.
Does the actual changes to tools::Rectangle.

I intend to land the first change (once Regina and Thorsten have weighed in), and then land the second change in stages, 
peeling off pieces to make bugfixing easier if we have regressions.

Caolán, I anticipate that this work will result in some work from crash-testing which will probably flush out more 
places that attempt to do computation on empty rectangles.

Regards, Noel.

More information about the LibreOffice mailing list