[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Polygon Objects



On Sat, 2004-02-21 at 20:36, Pete Shinners wrote:
> There is interest in getting this in Python. Things can get a little tricky 
> with shape classes because eventually a 'miraculous' design wants them all 
> communicating with each other and replaceable by others.

I think we're in general agreement about how this could fit in.  I don't
want a big "shape" library.  I would like to have a polygon class with
methods which make sense for polygons.  I'd like to use the pygame.Rect
class as a sort of template from which I will base the design.

I've begin to assemble a reference implementation for the "Polygon"
class in Python.  When I get it put together, I'll submit it to this
list, or email it to you.  Maybe then we can discuss whether this
feature is appropriate for pygame, any changes or revisions we need to
make, etc.

Finally, if everyone's happy with the code, we can drive the
implementation down into C and talk about pygame integration.

Does this sound good to you?

> I really don't think we need anything that amazing. A simple way to turn a 
> Rect into a 4 sided polygon, and create a Rect from a polygon bounding area 
> should be all that is needed. Then polygon functions can just deal with 
> other polygons and not try to be overly flexible.

Okay.  A rect->poly conversion would be useful, especially for people
who need to deal with non axis-aligned rectangles for collision
detection...

> It would still be best to clean up the Poly functions from the Python code 
> first. Got it anyplace people can peek? Collisions and Drawing are the only 
> two main features I think of for polygons. Other features might be things 
> like paths and booleans, but that starts to be more work. I think something 
> simple and elegent would be a better starting place.

That's the basic idea, but I'm not going to include drawing.  As it
stands, my Polygon objects (implemented in python) return a list
iterator with the __iter__ method, so they can be passed directly to
pygame.draw.polygon(...).  (At least this appears to be working for me.)

I'd like to pull some other algorithms together (especially polygon
clipping and "inflation").  I should be able to mail you some code later
this week.

Cheers.

Dave

-- 
David J. C. Beach
<beach@verinet.com>

Attachment: signature.asc
Description: This is a digitally signed message part