intersection of regions --- use java.awt.Rectangle

Asked by Bekir Dogru

Hi,
Sorry for bothering but I couldn't find any related "solved" problem for this subject...
I want to take intersection of two region as such:

desiredRegion = intersect( find("firstImage.png").right(), find("secondImage.png").below() )

the function intersect is the function that I want. Is there such way to get the same result with another function or algorithm?

Thank you for your help...

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
Bekir Dogru (bekirdogru) said :
#1

or may be some code as:

desiredRegion = between ( find("firstImage.png").right(200), find("firstImage.png").right(250) )

could be useful too but intersection is better...

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

not a Region feature yet ....

... but we have access to java.awt.rect

r1 = some_Region1
r2 = some_Region2

intersect = Region(r1.getRect().createIntersection(r2.getRect()))

for the available features see:
http://docs.oracle.com/javase/6/docs/api/java/awt/Rectangle.html

Revision history for this message
Bekir Dogru (bekirdogru) said :
#3

So as far as understood, I need to import java.awt.rect then I could obtain the intersection and I could find some image inside it?

Did I get it correct?

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

no import needed.

Region.getRect() returns a java.awt.Rectagle object, that knows how to do it ;-)

... and Region(java.awt.Rectangle) gets you back aRegion object.

So the above works out of the box.

Revision history for this message
Bekir Dogru (bekirdogru) said :
#5

Thanks RaiMan, that solved my question.

Revision history for this message
Bekir Dogru (bekirdogru) said :
#6

Thanks for your great work :)