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

Author Topic: [Solved] Can't get rectangle's intersects function to work?!  (Read 8851 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
So, (according to http://python-sfml.org/api/graphics.html#rectangle) I'm trying to do this :

but then I get this:
  File "graphics.pyx", line 188, in sfml.graphics.Rectangle.intersects (src/sfml\graphics.cpp:4442)
  File "graphics.pyx", line 97, in sfml.graphics.Rectangle.__init__ (src/sfml\graphics.cpp:2420)
TypeError: __init__() takes at most 2 positional arguments (4 given)

What's going on? I'm guessing the API documentation has not been fully updated for SFML2 since the example code yields the same results, if so, what arguments (types) should I pass?

I'm getting the rectangles using global_bounds btw.

Edit: I'm using python 2.7

-something python bindings-specific?-
« Last Edit: November 04, 2013, 10:16:19 am by Sonkun »


  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Can't get rectangle's intersects function to work?!
« Reply #1 on: May 09, 2013, 09:12:54 pm »
No that's a bug, thanks for discovering it.

Meantime, either override sf.Rectangle.intersects or maintain your own intersect function which should be as follow:

def intersects(self, rectangle):
        # make sure the rectangle is a rectangle (to get its right/bottom border)
        l, t, w, h = rectangle
        rectangle = Rectangle((l, t), (w, h))

        # compute the intersection boundaries
        left = max(self.left, rectangle.left)
        top = max(self.top, rectangle.top)
        right = min(self.right, rectangle.right)
        bottom = min(self.bottom, rectangle.bottom)

        # if the intersection is valid (positive non zero area), then
        # there is an intersection
        if left < right and top < bottom:
                return Rectangle((left, top), (right-left, bottom-top))

Tip: Create a file named "workaround.py" which lists and implements all these workarounds. Later, just delete it and you'll see what you have to change :)
Interested in using SFML with Python ? Try out its Python binding!


  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Can't get rectangle's intersects function to work?!
« Reply #2 on: May 10, 2013, 08:05:36 am »
Yeah, figured that out, thanks!
I hope the bug-fixes would come out soon though; is there a place I can report them directly, a public repo or something? also are there any other python bindings currently active?


  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Can't get rectangle's intersects function to work?!
« Reply #3 on: May 22, 2013, 04:48:24 pm »
Both your questions depend on your definition of either. As for bugfixes coming out soon, You can always download the git version of python-sfml which will always have the latest changes applied to them (unless Jonathan forgets to push them from his local machine xD). Historically though, there haven't been bugfix releases, but I suspect thats a policy that easy enough to change if Jonathan and I see that such bugs are impacting the community, and thus the use of these bindings.

As for there being another "active", I guess there is Bastien's bindings [1], but he hasn't made any commits since Februrary. I don't know whether thats because he considers them stable, or has stopped developing them.

If I can, may I ask what in particular asked you to ask that question? Are you finding our documentation, featureset, or anything else lacking and in need of some love? If so, feel free to report an issue in our bug tracker [2]. Jonathan and I are opinionated, but open-minded individuals (oxymoron?), who love feedback.


PS, don't let the initial number of issues scare you away, only 8 are active issues, and of those 8, 0 are actual bugs (they are all documentation related)


  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: [Solved] Can't get rectangle's intersects function to work?!
« Reply #4 on: July 21, 2014, 10:42:09 pm »
Sorry to ressurect an old thread, but this bug is still present in the 1.3 release version for windows on python-sfml which I downloaded recently.  Considering it's over a year since the original problem was posted is there going to be a new release of the bindings anytime soon?  I see a lot of commits in the github repository. 

This bug strikes me as a particularly ugly one as it's the primary way collision detection in simple 2d games would be performed.  The work around you posted is nice and simple, but it's a shame to have to have it for something which seems like such a core piece of functionality in the API.