koffice/krita/ui/canvas

Dmitry Kazakov dimula73 at gmail.com
Mon Feb 1 23:11:50 CET 2010


On Tue, Feb 2, 2010 at 12:37 AM, Adrian Page <adrian at pagenet.plus.com>wrote:

>
> On 1 Feb 2010, at 11:08AM, Dmitry Kazakov wrote:
>
> It gives the desired result - the smallest integer rectangle containing the
>> QRectF. That's what we're after.
>>
>
> No, it doesn't. Because truncating and adding 0.5 is not stable over
> scaling. Just right over the thing we do in KisImage.
>
> Example:
>
> QPointF convertToQPointF(QPoint pt) {
>     return QPointF((pt.x()+0.5)*2, (pt.y()+0.5)*2);
> }
>
> QRectF convertToQRectF(QRect rc) {
>     return QRectF(convertToQPointF(rc.topLeft()),
> convertToQPointF(rc.bottomRight()));
> }
>
> void main()
> {
>     QRect rect(0,0,6,4);
>     qDebug()<<"intRect:"<<rect<<rect.topLeft()<<rect.bottomRight();
>
>     QRectF floatRect(convertToQRectF(rect));
>
> qDebug()<<"floatRect:"<<floatRect<<floatRect.topLeft()<<floatRect.bottomRight();
>
>     QRect alignedRect(floatRect.toAlignedRect());
>
> qDebug()<<"alignedRect:"<<alignedRect<<alignedRect.topLeft()<<alignedRect.bottomRight();
> }
>
> The result will be the following:
> intRect: QRect(0,0 6x4) QPoint(0,0) QPoint(5,3)
> floatRect: QRectF(1,1 10x6) QPointF(1, 1)QPointF(11, 7)
> alignedRect: QRect(1,1 10x6) QPoint(1,1) QPoint(10,6)
>
>
> That is surely NOT what we desired. (btw, this example is almost a piece
> code from KisImage
>
>
> Well, you've written your own convertToQRectF() and written it wrong ;-). I
> just checked krita and there is no QRect to QRectF conversion function, and
> the reason is none is required - it's simply QRectF(QRect).
>

QPointF KisImage::pixelToDocument(const QPoint &pixelCoord) const
{
    return QPointF((pixelCoord.x() + 0.5) / xRes(), (pixelCoord.y() + 0.5) /
yRes());
}

Now i doubt it is called from somewhere. But it is present there. Maybe just
remove it then? QPoint->QPointF will be translated automatically.

 You're mixing up concepts in your function as converting the opposite
> corner points as points, then putting those into a QRectF gives a different
> kind of conversion. You're effectively scaling the QRectF(0.5, 0.5, 5, 3) by
> 2, and getting the result QRectF(1, 1, 10, 6) - which is right. And QRect(1,
> 1, 10, 6)  is the correct conversion back to QRect.
>
> Converting rectangles is different to converting points. The QRectF(0.0,
> 0.0, 6.0, 4.0) is the correct conversion of the QRect(0, 0, 6, 4). It is the
> rectangle equal to the border of the 6x4 rectangle. And if you scale it by
> 2, you get QRectF(0, 0, 12, 8) - the border of the double sized QRect(0, 0,
> 6, 4).
>

Why do you add 0.5 then? =)



> Well, you've helped convince me that QRectF(QRect) is correct,
> and toAlignedRect() is correct, so I don't see a huge problem.
>

Great! But still why 0.5? %)




-- 
Dmitry Kazakov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/kimageshop/attachments/20100202/e713a860/attachment.htm 


More information about the kimageshop mailing list