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

Author Topic: Rect with negative width  (Read 2912 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 5
    • View Profile
Rect with negative width
« on: May 04, 2012, 02:33:33 am »
I did some searching on the forum, but "Rect" "Intersect" "Negative" and the like are not the best search terms, so I apologise if this has been noted.

I held off posting on the tracker because I wanted to check if this is by design or a bug. If this is a bug I will happily toodle off to the Github and submit a patch.

Rectangles with a negative width/height do not seem to intersect properly with rectangles with positive width/height. For example, a rectangle at 0,0 with width and height of 10 should intersect with a rectangle at 15, 15 with a width and height of -10. In SFML they do not.

Here is the obligatory code snippet:
Code: [Select]
#include <SFML/System.hpp>
#include <iostream>

int main(int argc, char *argv[]) {

// intersect test
sf::IntRect rect1(0,0,10,10); //Rectangle at 0,0 with width of 10 and height of 10
sf::IntRect rect2(15,15,-10,-10); //Rectangle at 15,15 with width of -10 and height of -10
bool test1 = rect1.intersects(rect2);
std::cout << "Test 1 " << test1 << std::endl;
return 0;
The output is:
Code: [Select]
Test 1 0

So clearly, the rectangles are considered to not intersect. Is this the intent?

For anyone interested in a more involved test, I've attached a .cpp that checks a couple different combinations.

[attachment deleted by admin]


  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Rect with negative width
« Reply #1 on: May 04, 2012, 07:56:15 am »
I think it was intented at the beginning, but now it could definitely be corrected :)
Laurent Gomila - SFML developer