KRect and KRectF proposal

Thiago Macieira thiago at kde.org
Thu Apr 9 05:43:08 BST 2026


On Wednesday, 8 April 2026 07:29:11 Pacific Daylight Time Vlad Zahorodnii 
wrote:
> Negative width and height are a corner case. I'm sure you can encounter
> them, e.g. in some drawing applications when the user presses and drags
> the pointer to draw a rectangle, but I don't think they are so common
> that the core abstraction needs to handle that. For example, in KWin, we
> have no valid case where rectangles with negative sizes are okay, and it
> is a project that uses rectangles heavily.

I don't know why they were added to QRect/QRectF. It was before the public 
history. But regardless, it's API now and may be in use. So unless you declare 
it broken/misfeature, it should be supported.

> > Consider:
> > top() = -0.4999
> > left() = -0.4999
> > bottom() = 0.4999
> > right() = 0.4999
> > 
> > width() and height() are 0.9998, which clearly rounds to 1.0. But all of
> > the four coordinates round to 0.
> 
> Correct, whether it's fine depends on the context though.

And I'm arguing it shouldn't be context-dependent. You can easily round in 
such a way that it prevents becoming empty. Just round towards positive 
infinity.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 870 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-devel/attachments/20260408/322933ca/attachment.sig>


More information about the kde-devel mailing list