Pattern.similar resets targetOffset to (0,0) --- workaround

Asked by Justin Martin

********* workaround

only Pattern p = some-other-pattern.similar().targetOffset() works

so only if Pattern.targetOffset() is the last action in a given Pattern, targetOffset is remembered.

----------------------------------------------------------------------------------------------------------------------------------
Sikuli Version: Sikuli X 1.0rc2 "Maltese"
Operating System: Windows 7 32 bit

Steps to reproduce:

           Screen sikuli = new Screen();
           Pattern testPattern = new Pattern("DFWizard.DFName.PNG");
           testPattern.similar(0.95f);
           testPattern.targetOffset(30,0);
           sikuli.doubleClick(testPattern,0);
           sikuli.type(testPattern,dfName,0);

When I do this, sikuli is not using the specified offset of 30 pixels. It should be offset of 30 pixels. Please fix this in the java api.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

not a bug

Revision history for this message
RaiMan (raimund-hocke) said :
#2

Pattern.similar() and Pattern.targetOffset() do not change the respective attributes of the given Pattern, they return a new Pattern object.

you have to say:

           Screen sikuli = new Screen();
           Pattern testPattern = new Pattern("DFWizard.DFName.PNG");
           testPattern = testPattern.similar(0.95f).targetOffset(30,0);

Revision history for this message
Justin Martin (justin-martin) said :
#3

RaiMan,
This has not solved the problem for me.
I think the problem is that the first setting gets ignored. For example, if I do the following:
testPattern = testPattern.targetOffset(30,0).similar(0.95f);

Then my targetOffset is ignored and the similarity is honored. So although your example works for me, I'm skeptical that the similarity setting is being honored. If you try this scenario given in my above code, you will see that the targetOffset is not being honored. Or do you have to make the calls in the exact order that you have given in your example?
Thanks for your speedy response!

Revision history for this message
RaiMan (raimund-hocke) said :
#4

That's strange. I will have a look at it.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#5

You are right, but this is a bug. I will report it.
(giving similar() seems to reset targetOffset to (0,0))

So currently only p3 works as expected, p4 is buggy.

[code]
Pattern p = new Pattern("image.png");
Pattern p1 = p.similar((float) 0.99);
Pattern p2 = p.targetOffset(10,0);
Pattern p3 = p.similar((float) 0.99).targetOffset(10,0);
Pattern p4 = p.targetOffset(10,0).similar((float) 0.99);

System.out.println(p);
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
System.out.println(p4);

[result]
Pattern("image.png").similar(0.7)
Pattern("image.png").similar(0.99)
Pattern("image.png").similar(0.7).targetOffset(10,0)
Pattern("image.png").similar(0.99).targetOffset(10,0)
Pattern("image.png").similar(0.99)

Revision history for this message
RaiMan (raimund-hocke) said :
#6

bug and workaround

Revision history for this message
Justin Martin (justin-martin) said :
#7

Thanks RaiMan, that solved my question.