New-be here, sorry if I do anything I should not. Just let me know and I will try to shape up.
It might be something really easy, but I can not figure out why the two methods of checking if a point is in a RectShape are giving me different answers.
The RectShape.Contains Method does not return what I perceive as the right answer.
So I followed it with the code below. That code gives me the a True if the point passed are in the RectShape,
But Contains only returns a True, if it is in the Upper-Left 1/4 of the passed rectangle. Even though the debugger shows all the variable should cause Contains to return a True.
They give different answers. What am I missing?
(if you change the two 30s to 10s then the results are the same.)
Var tempBoo as Boolean
Var myXXRect as New RectShape
Var myX as Double = 30.
Var myY as Double = 30.
myXXRect.x = 0
myXXRect.y = 0
myXXRect.Width = 50
myXXRect.Height = 50
tempBoo = myXXRect.Contains(myX,myY)
if tempBoo then MessageBox (“First one is True”)
tempBoo = False
if (myX >= myXXRect.x) then
if (myX <=( myXXRect.x + myXXRect.width) ) then
if ( myY >= myXXRect.y ) then
if (myY <=( myXXRect.y + myXXRect.height) ) then
tempBoo = True
if tempBoo then MessageBox (“Second one is True”)
Hi Bobby, welcome to the forum
When pasting code make sure to use the </> code button from the toolbar to make it easier to read.
I tried your code and it looks like RectShape’s size depends on the scale of the screen. I am running a Retina macbook and I guess you are too. As this isn’t described in the Xojo docs, I suspect it is a bug.
Are you using that code for drawing?
If you are, set
myXXRect.Scale = g.ScaleX
If not, I would recommend using the Rect class instead of RectShape.
Rect class also has a Contains method: https://documentation.xojo.com/api/graphics/rect.html#rect-contains
Thank you so much Jeremie.
Glad I am not crazy. (well about this anyway.)
The code is only a test program I wrote to post. I had been working on something for weeks and it took me much to long to narrow it down to the Contains. I guess I trusted Xojo a little to much. or had to little confidence in me. I wrote and re-wrote code thinking I just had some variable messed up.
If it is a bug, is Xojo good about cleaning stuff like that up. Or documenting it?
Thanks for the time about </>
I am not using that code for drawing, only to change data if the mouse is clicked in the rectangle. (Lots of them, with each one changing different things.) So in my App, I was clinking and getting the right results sometimes, but if I clicked a little to low or to the right, I got results that took a while to trace back after finding data that did not match what I wanted… It has been a learning experience.
I am actually on a 5K iMac. But I will try to get up to speed on Scale.
For every 1 thing I learn, I realize that there are 5 more that I need to learn.
In the meantime I will probably just make a “myContains" and use it. But if I find out that I should be setting scale rather than “assuming it,” I will.
I might go back to Rect from RectShape. Actually am using my own class because each rectangle in a grid has a few switches and some data added to it. I am not sure right at this second why I switch to RectShape. But will revisit it.
Thank you again.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.