Determine if two RealBasic.Rect objects are equal

I know I can do this…

  If r.left<>r2.left Or _
  r.top<>r2.top Or _
  r.width<>r2.width Or _
  r.height<>r2height Then changed=True

but with all the other RECT goodies, I was hoping there was a easier (and faster) way?

Psst try putting code inside [code] blocks on the forum! It makes them formatted nicely!

An example code block where things are monospaced and indented!

was hoping for something more like

if R.EQUALS(r2) then 

write an extension method once & use it as you describe

but no it doesnt exist

Why do I have a Rect.Equal method available to me? Some plugin?

if r1.Equal( r2 ) then // this works for me

[quote=164433:@Kem Tekinay]Why do I have a Rect.Equal method available to me? Some plugin?

if r1.Equal( r2 ) then // this works for me [/quote]
Must be
Its not in the frameworks

Looks like one of the free functions from Einhugur.

It does not work here. "Type Realbasic.Rect has no member named “equal”.

But this works fine :

if r1 = r2 then

No, that doesn’t identify two different rects with the same dimensions. I tested.

Right, surely that’s just going to test if the two variables point to the same actual object.

It would nice if you could use an extension method to extend Operator_Compare and the like to native classes.

I may be stupid, but this says “equal” :

[code] dim r1 as new realbasic.rect(0,0,100,75)
dim r2 as new realbasic.rect(0,0,100,75)

if r1 = r2 then
msgbox “equal”
else
msgbox “not equal”
end if[/code]

If I change a dimension on one of the rectangles, I get “not equal”…

Operator_Compare is implemented in the Xojo framework, so it works to use =.

Well, I’ll be. Michel, try it again without the “realbasic” namespace. We are seeing two different behaviors here.

  dim r1 as new Rect(0,0,100,75)
  dim r2 as new Rect(0,0,100,75)
  
  if r1 = r2 then
    msgbox "equal"
  else
    msgbox "not equal"
  end if

That’s how I originally tested it.

[quote=164452:@Kem Tekinay]Well, I’ll be. Michel, try it again without the “realbasic” namespace. We are seeing two different behaviors here.

  dim r1 as new Rect(0,0,100,75)
  dim r2 as new Rect(0,0,100,75)
  
  if r1 = r2 then
    msgbox "equal"
  else
    msgbox "not equal"
  end if

That’s how I originally tested it.[/quote]

It does not even execute. “Can’t find a type with this name”. Maybe you have a Rect class in your plugins somewhere ?

I guess so. I wish everyone would either use namespaces or otherwise distinguish their method/class names.

[quote=164441:@Michel Bujardet]I may be stupid, but this says “equal” :

[code] dim r1 as new realbasic.rect(0,0,100,75)
dim r2 as new realbasic.rect(0,0,100,75)

if r1 = r2 then
msgbox “equal”
else
msgbox “not equal”
end if[/code]

If I change a dimension on one of the rectangles, I get “not equal”…[/quote]
The above is also correct when using xojo.core.rect on iOS.

That was a recent proposition from Christian. Guess in Einhugur’s time it was less of a concern.