<br><br><div class="gmail_quote">On Mon, Feb 1, 2010 at 1:27 AM, Adrian Page <span dir="ltr">&lt;&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="word-wrap: break-word;"><br><div><div class="im"><div>On 31 Jan 2010, at 7:13PM, Dmitry Kazakov wrote:</div><br><blockquote type="cite"><div class="gmail_quote">On Sun, Jan 31, 2010 at 2:53 AM, Adrian Page <span dir="ltr">&lt;&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>
Dmitry Kazakov wrote:<br>
&gt; I thing this should be reverted according to Qt&#39;s QRect tradition, i.e.<br>
&gt; (5,7)-&gt;(5.0,7.0). Or change ALL the Krita&#39;s code that uses<br>
&gt; QRectF::toAlignedRect() or QRectF(intRect) to a new type of conversion.<br>
&gt; Other way we&#39;ll dig a deep grave for ourselves using two completely<br>
&gt; different coordinate systems throughout the code.<br>
<br>
</div>This is the way krita has worked for the last however many years.</blockquote><div><br></div><div>Well, not everywhere. Please take a look into KisImage::documentToIntPixel(). It uses QRectF::toAlignedRect(). So it does just the opposite to what you are saying.</div>
</div></blockquote><div><br></div></div>It gives the desired result - the smallest integer rectangle containing the QRectF. That&#39;s what we&#39;re after.</div></div></blockquote><div><br>No, it doesn&#39;t. Because truncating and adding 0.5 is not stable over scaling. Just right over the thing we do in KisImage.<br>
<br>Example:<br><br>QPointF convertToQPointF(QPoint pt) {<br>    return QPointF((pt.x()+0.5)*2, (pt.y()+0.5)*2);<br>}<br><br>QRectF convertToQRectF(QRect rc) {<br>    return QRectF(convertToQPointF(rc.topLeft()), convertToQPointF(rc.bottomRight()));<br>
}<br><br>void main()<br>{<br>    QRect rect(0,0,6,4);<br>    qDebug()&lt;&lt;&quot;intRect:&quot;&lt;&lt;rect&lt;&lt;rect.topLeft()&lt;&lt;rect.bottomRight();<br><br>    QRectF floatRect(convertToQRectF(rect));<br>    qDebug()&lt;&lt;&quot;floatRect:&quot;&lt;&lt;floatRect&lt;&lt;floatRect.topLeft()&lt;&lt;floatRect.bottomRight();<br>
<br>    QRect alignedRect(floatRect.toAlignedRect());<br>    qDebug()&lt;&lt;&quot;alignedRect:&quot;&lt;&lt;alignedRect&lt;&lt;alignedRect.topLeft()&lt;&lt;alignedRect.bottomRight();<br>}<br><br>The result will be the following:<br>
intRect: QRect(0,0 6x4) QPoint(0,0) QPoint(5,3)<br>floatRect: QRectF(1,1 10x6) QPointF(1, 1)QPointF(11, 7)<br>alignedRect: QRect(1,1 10x6) QPoint(1,1) QPoint(10,6)<br><br><br>That is surely NOT what we desired. (btw, this example is almost a piece code from KisImage)<br>
<br>What do i want to say? <br>1) If we decide to use Qt&#39;s style, we must not use these additional (+0.5) anywhere in the code. More than that, we can&#39;t even use bottomRight() function of QRect for scaling due to the &quot;historical reasons&quot; mentioned in Qt&#39;s documentation for QRect. We should scale width() and height() of the rect instead.<br>
<br>2) If we decide to stay with the majority of the flow, we should remove all the traces of QRectF from Krita&#39;s code, for not confusing coders and eliminate their temptation to use toAlignedRect().<br><br> <br></div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div><div>No, you shouldn&#39;t need to round. If you are rounding, then you will be losing pixels when whatever number you&#39;re rounding is &gt; x.0 and &lt; x.5.</div>
</div></div></blockquote><div><br>You won&#39;t loose anything if you use math for this =) You shouldn&#39;t add exactly 0.5. You should add (0.5-EPS), where EPS=1e-10.<br>In such a case you&#39;ll get stable scale operation and no pixels will be lost.<br>
<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div><div> Floor() and ceil() gives the stability without ever losing pixels, that&#39;s what  toAlignedRect() is doing. And floor() is the the truncating bit (for points).</div>
</div></div></blockquote></div><br>But not stable over scaling.<br clear="all"><br>-- <br>Dmitry Kazakov<br>