Another newbie question

Alex Martelli aleax at mail.comcast.net
Sat Dec 10 21:11:20 EST 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
   ...
> I could imagine using Python's built-in complex numbers to represent
> 2D points.  They're immutable, last I checked.  I don't see a big
> conflict.

No big conflict at all -- as I recall, last I checked, computation on
complex numbers was optimized enough to make them an excellent choice
for 2D points' internal representations.  I suspect you wouldn't want to
*expose* them as such (e.g. by inheriting) but rather wrap them, because
referring to the .real and .imag "coordinates" of a point (rather than
.x and .y) IS rather weird.  Wrapping would also leave you the choice of
making 2D coordinates a class with mutable instances, if you wish,
reducing the choice of a complex rather than two reals to a "mere
implementation detail";-).

The only issue I can think of: I believe (I could be wrong) that a
Python implementation might be built with complex numbers disabled (just
like, e.g., it might be built with unicode disabled).  If that's indeed
the case, I might not want to risk, for the sake of a little
optimization, my 2D geometry framework not working on some little
cellphone or PDA or whatever...;-)


Alex



More information about the Python-list mailing list