I have been stuck for a couple of days now trying to discover my issue with handling guides and I think I found it.
Using the command “setHorizontalGuides” and “setVerticalGuides” they do not apply the correct values given into Krita so when I read them again they are different instead of being equal. so this causes an error.
The issue is that when you apply a new set of guides, randomly on certain values like number.0000000001 it will round as number.00000000013 and then on the next apply it will round into another random and then into another random.
The amount of times it does this is unpredicatable and impossible to stop.
I have tried to force the value into a integer so it would be just int(number) and also have tried to set the values to round(number,1) so it would not go on a train of zero decimals and it would be closer to the value it needs to be. However doing any of these do a infinite loop because on that given number it will always apply the value wrong instead of stabilizing on the probably nearest stable value that does not change after a couple of cycles.
Krita output
In this image you can see one of the cycles that messed up and needed 5 cycles to stabilize into correct values. The code only reads Krita. Sorts the values between themselves (no change to the values within the script) and considering there was a sorting event it applies the values back into Krita so they are organized. which causes the random cycle that can cause infinite loops on more complex changes. I moved with the mouse a guide within Krita’s canvas and this is my addon trying to coupe with that change, and it stops updating once there are no new values. The new values are underlined with red.
Variables
Cycle - Number of the plugin cycle to update
Krita - Guide list read from Krita
Previous - Scripts memory of previous cycle so it compares to the current cycle and decides how to operate (no operations are done in this example)
Sort - Sorting operation that alters the order of the values.
Next - The value that should be read by Krita on the next Cycle.
Python code check
1 - create a new document size 1000x1000
2 - Open Scripter and run this Python code
import krita
ad = Krita.instance().activeDocument()
list = [222.00000000000001, 344.00000000000002, 472.00000000000003, 515.0000000000001, 583.0000000000002, 609.0000000000003]
ad.setHorizontalGuides(list)
guides = ad.horizontalGuides()
print(guides)
Output
[222.00000000000003, 344.00000000000006, 472.0000000000001, 515.0000000000001, 583.0000000000002, 609.0000000000003]
As you can see the first 3 values in the list changed and the last 3 values in the list did not change.
I should add that this list of values was created by moving guides on the canvas.
Observations:
I understand why float is being used for the Guides however their value usage of it seems very inconsistent this due to the fact that their location is in between pixels by force of the system so instead of 222.00000000000003 why is it not 222.00000000000000 or 222.0 alone on all values? This is what puzzles me the most, as this in-between pixel snapping should round the values to 222.0.
Snapping





