Fix rounding in wrap around mode for some operations
ClosedPublic

Authored by alvinhochun on Nov 19 2017, 7:28 AM.

Details

Summary

Fix the rounding error of negative coordinates in wrap around mode for some operations, e.g. colour picker and fill tool.

Ref: https://bugs.kde.org/show_bug.cgi?id=383894

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
alvinhochun created this revision.Nov 19 2017, 7:28 AM
alvinhochun edited the summary of this revision. (Show Details)
alvinhochun edited the test plan for this revision. (Show Details)

P.S. there is a QPoint KisImage::documentToIntPixel( const QRectF &) overload which I haven't touched. With a quick search it seems to be unused, and I have no clue if it needs fixing or not.

rempt added a subscriber: rempt.Nov 19 2017, 11:29 AM
P.S. there is a `QPoint KisImage::documentToIntPixel( const QRectF &)` overload which I haven't touched. With a quick search it seems to be unused, and I have no clue if it needs fixing or not.

If it's not used, it should be removed.

In D8894#169531, @rempt wrote:
P.S. there is a `QPoint KisImage::documentToIntPixel( const QRectF &)` overload which I haven't touched. With a quick search it seems to be unused, and I have no clue if it needs fixing or not.

If it's not used, it should be removed.

OK, I've removed it.

dkazakov accepted this revision.Nov 20 2017, 2:00 PM
dkazakov added a subscriber: dkazakov.

Please change the rounding to 'nearest' and push :)

libs/image/kis_image.cc
944

It should return return pixelCoord.toPoint() instead, that is "round to nearest". Otherwise, the coordinate will not coincide with the results returned by KisCoordinatesConverter.

This revision is now accepted and ready to land.Nov 20 2017, 2:00 PM
alvinhochun added inline comments.Nov 20 2017, 2:28 PM
libs/image/kis_image.cc
944

Really though? I just tried this and the colour picker is offset by half a pixel, for both positive and negative coords.

dkazakov added inline comments.Nov 21 2017, 7:31 AM
libs/image/kis_image.cc
944

Then it looks like there is something wrong. Either is color picker or in KisCoordinatesConverter. We need to discuss that on IRC some time this week

alvinhochun added inline comments.Nov 25 2017, 10:10 AM
libs/image/kis_image.cc
944

I think it's not the color picker; the fill tool and the contiguous selection tool also use the same way to transform the coordinates.from the KoPointerEvent.

The source point of the KoPointerEvent seems to come from KisToolProxy::widgetToDocument which in turn appears to be from KisCoordinatesConverter.

Seeing that QPointF KisImage::pixelToDocument(const QPoint &pixelCoord) const returns QPointF((pixelCoord.x() + 0.5) / xRes(), (pixelCoord.y() + 0.5) / yRes()), using qFloor here seems to be the right choice, and it does work correctly, so it would seem to coincide with KisCoordinatesConverter, wouldn't it?

alvinhochun marked 4 inline comments as done.

As discussed on IRC, the floor rounding is correct, but the related functions are now renamed for clarity

dkazakov accepted this revision.Nov 30 2017, 10:41 AM

Looks perfectly fine to push now! :)

This revision was automatically updated to reflect the committed changes.