Author: ArcRiley Date: 2008-03-11 21:09:41 -0400 (Tue, 11 Mar 2008) New Revision: 1137
Modified: trunk/pysoy/src/_datatypes/BodyPosition.pxi Log: Ticket #946 : * basically rewrote __richcmp__ Modified: trunk/pysoy/src/_datatypes/BodyPosition.pxi =================================================================== --- trunk/pysoy/src/_datatypes/BodyPosition.pxi 2008-03-12 00:40:18 UTC (rev 1136) +++ trunk/pysoy/src/_datatypes/BodyPosition.pxi 2008-03-12 01:09:41 UTC (rev 1137) @@ -186,40 +186,55 @@ value[1] % _position[1], value[2] % _position[2])) - def __richcmp__(BodyPosition self, BodyPosition that, oper) : - if not isinstance(that, soy._datatypes.BodyPosition) : - return NotImplemented - cdef float* _position, _that_position[3] + def __richcmp__(BodyPosition self, that, int _oper) : cdef int _x, _y, _z + cdef float* _positionA + cdef float* _positionB + # + # handle type mismatch first + if not isinstance(that, BodyPosition) : + # return true only when the operation is != + return _oper == 3 + # + # assign _positionA and _positionB if self._body == NULL : - _position = self._position + _positionA = self._position else : - _position = (<soy.bodies.Body> self._body)._position - if self._position == that._position : - stdio.printf("Yay") + _positionA = (<soy.bodies.Body> self._body)._position + if (<BodyPosition> that)._body == NULL : + _positionB = (<BodyPosition> that)._position else : - stdio.printf("%f \n",(<soy.bodies.Body> that._body)._position) - if that._body == NULL : - _that_position = that._position - else : - _that_position = (<soy.bodies.Body> that._body)._position - _x = (_position[0] <= _that_position[0], - _position[0] == _that_position[0], - _position[0] == _that_position[0], - _position[0] >= _that_position[0])[oper] - _y = (_position[1] <= _that_position[1], - _position[1] == _that_position[1], - _position[1] == _that_position[1], - _position[1] >= _that_position[1])[oper] - _z = (_position[2] <= _that_position[2], - _position[2] == _that_position[2], - _position[2] == _that_position[2], - _position[2] >= _that_position[2])[oper] - if oper == 3 : - return (True, False)[_x&_y&_z] - else : - return (False, True)[_x&_y&_z] + _positionB = (<soy.bodies.Body> (<BodyPosition> that)._body)._position + # + # < operand + if _oper == 0 : + return False + # + # <= operand + if _oper == 1 : + return False + # + # == operand + if _oper == 2 : + return (False, True) [_positionA[0] == _positionB[0] + and _positionA[1] == _positionB[1] + and _positionA[2] == _positionB[2]] + # + # != operand + if _oper == 3 : + return (True, False) [_positionA[0] == _positionB[0] + and _positionA[1] == _positionB[1] + and _positionA[2] == _positionB[2]] + # + # > operand + if _oper == 4 : + return False + # + # >= operand + if _oper == 5 : + return False + def __neg__(BodyPosition self) : if self > 0 : return self *-1 _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn