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

Re: [pygame] 2D Vector Class



On 5/16/07, Ulf Ekström <uekstrom@xxxxxxxxx> wrote:
> So far I"ve found this one on the wiki (anybody know who wrote this?):
>
I posted the one on the wiki


This looks a bit slow, but on the other hand it has support for
operations I didn't even know I wanted to do on 2-vectors.

I've changed it since to use slots (stole that idea from somebody else
who posted about vector classes on the mailing list) and slots is much
much faster on 2.5. I'll probably update that wiki thing with that
version when I'm at home.

as far as it having lots of vector functions (like projection &
interpolation), that is very deliberate. I find it results in highly
readable code when doing a lot of vector operations, because the code
is much shorter and appropriate math terms are used (cause they are
the function names)


looks like it doesn't support vector scaling, which is a bit of a
bummer; one reason for me to have 2-vectors is so that I can write

That code actually supports multiplication by a scalar just fine. The
typeerror except falls through to scalar operations after trying a
vector op with array indexing. I think the version of that code that I
actually use now is much clearer about how that happens though
(checking for an indexing op is faster than the try/except)


I don't mean to bash the author of that code, but a fast vector
implementation which is designed for "physics" would be nice to have.

You're not bashing anyone. I am curious though - what qualifies as
"designed for physics"?


The complex number trick was very clever!

That seems very smart, and I imagine it is very fast...

I wonder if there is a good way to keep it fast, but also let you mix
the vectors with tuples, i.e.:
a = vector2(3,5)
b = a + (2,2)
and have that work/make sense...