Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Rectangle intersection returning a weird value  (Read 1984 times)

0 Members and 1 Guest are viewing this topic.

montez

  • Newbie
  • *
  • Posts: 2
    • View Profile
Rectangle intersection returning a weird value
« on: January 12, 2016, 07:42:20 pm »
Hi, I'm using sfml for a while in personal game projects, and I'm stuck with the intersection method from Rect<T>.
The rectangles :
sf::IntRect(sf::Vector2i(7, 7), sf::Vector2i(11, 11));
sf::IntRect(sf::Vector2i(10, 14), sf::Vector2i(16, 22));

for some reason they're intersecting each other. I may be wrong, but it shouldn't happen.

Thanks for your help!

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Rectangle intersection returning a weird value
« Reply #1 on: January 12, 2016, 08:06:31 pm »
They do in fact intersect:

The first box is positioned at: 7,7 with a size of 11,11
The second box ist positioned at: 10,14 with a size of 16,22

With this information you get:


If you use 2 vectors as function arguments the first one refers to the position and the second one refers to the size.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Rectangle intersection returning a weird value
« Reply #2 on: January 12, 2016, 08:08:32 pm »
The second parameter is the size, not the other corner, so a rectangle that starts at (7,7) and has a size of 11x11, will intersect a rectangle which has a corner at (10,14).
Edit: Damn it, you beat me to it.

montez

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Rectangle intersection returning a weird value
« Reply #3 on: January 12, 2016, 09:22:12 pm »
True... I was using "position/size" for the logical coordinates and "position/position" for drawing coordinates, so it was showing correctly, but logicaly it was wrong.

Thanks for poiting that out and sorry for the trouble.

 

anything