[Tutor] line class
Alan Gauld
alan.gauld at btinternet.com
Wed Jul 9 09:05:57 CEST 2008
"Christopher Spears" <cspears2002 at yahoo.com> wrote
> def __cmp__(self, other):
> if self.x == other.x and self.y == other.y:
> return 0
> elif self.x < other.x and self.y < other.y:
> return -1
> elif self.x > other.x and self.y > other.y:
> return 1
Rather than comparing in that manner I'd take a different approach.
I'd measure the length from the origin thus any point that was inside
the circle upon whose ciorcumference the point sits is less than
the point. Any point on the circumference is equal and any point
outside the circle is greater...
[ Another approach with similar results is to convert the coordinates
into complex numbers and then use the complex number cmp method
to compare those. ]
Alan G.
More information about the Tutor
mailing list