On Tue, Jul 8, 2008 at 3:29 PM, Christopher Spears &lt;<a href="mailto:cspears2002@yahoo.com">cspears2002@yahoo.com</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have been reading everyone&#39;s comments on my line class. &nbsp;I have decided to implement some of the suggestions. &nbsp;Someone suggested that I create a Point.__cmp__ method. &nbsp;Here is what I have so far:<br>
<br>
def __cmp__(self, other):<br>
 &nbsp; &nbsp; &nbsp; &nbsp;if self.x == other.x and self.y == other.y:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 0<br>
 &nbsp; &nbsp; &nbsp; &nbsp;elif self.x &lt; other.x and self.y &lt; other.y:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return -1<br>
 &nbsp; &nbsp; &nbsp; &nbsp;elif self.x &gt; other.x and self.y &gt; other.y:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 1<br>
<br>
Figuring out the results for the above situations was easy. &nbsp;However, what should I do with the following situations:<br>
self.x &gt; other.x and self.y &lt; other.y<br>
self.x &lt; other.x and self.y &gt; other.y<br>
</blockquote><div><br>Sorry to jump in late - I missed the first part of the discussion - but what do you want to achieve with a Point.__cmp__ method?&nbsp; <br><br>Is it just to determine whether two points are identical - in which case I&#39;d write it like so:<br>

def __cmp__(self, other):<br>&nbsp;&nbsp;&nbsp; if (self.x == other.x) and (self.y == other.y): <br>

 &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return True<br>&nbsp;&nbsp;&nbsp; else:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return False<br>
<br>
<br></div></div>Or are you trying to determine the slope of the line between two points, in which case I&#39;d write it like this:<br>
def __cmp__(self, other):<br>&nbsp;&nbsp;&nbsp; if self.x == other.x:<br>

 &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return False # points are identical, or one above the other - slope is undefined<br>&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (self.y - other.y) / (self.x - other.x) # rise over run<br>
<br>or... or... or...&nbsp; First decide what you want out of it, then write the function/method to give you the result you want.<br>
<br>-- <br><a href="http://www.fsrtechnologies.com">www.fsrtechnologies.com</a>