Commit 22094151 authored by sumpfralle's avatar sumpfralle

added a comparison function for cutters


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@173 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6b485381
...@@ -24,6 +24,18 @@ class BaseCutter: ...@@ -24,6 +24,18 @@ class BaseCutter:
def __repr__(self): def __repr__(self):
return "BaseCutter" return "BaseCutter"
def __cmp__(self, other):
""" Compare Cutters by shape and size (ignoring the location)
This function should be overridden by subclasses, if they describe
cutters with a shape depending on more than just the radius.
See the ToroidalCutter for an example.
"""
if isinstance(other, BaseCutter):
return cmp(self.radius, other.radius)
else:
# just return a string comparison
return cmp(str(self), str(other))
def moveto(self, location): def moveto(self, location):
self.location = location self.location = location
self.minx = location.x-self.radius self.minx = location.x-self.radius
......
...@@ -30,6 +30,16 @@ class ToroidalCutter(BaseCutter): ...@@ -30,6 +30,16 @@ class ToroidalCutter(BaseCutter):
def __repr__(self): def __repr__(self):
return "ToroidalCutter<%s,%f,R=%f,r=%f>" % (self.location,self.radius,self.majorradius,self.minorradius) return "ToroidalCutter<%s,%f,R=%f,r=%f>" % (self.location,self.radius,self.majorradius,self.minorradius)
def __cmp__(self, other):
""" Compare Cutters by shape and size (ignoring the location) """
if isinstance(other, ToroidalCutter):
# compare the relevant attributes
return cmp((self.radius, self.majorradius, self.minorradius),
(other.radius, other.majorradius, other.minorradius))
else:
# just return a string comparison
return cmp(str(self), str(other))
def get_shape(self, format="ODE", additional_distance=0.0): def get_shape(self, format="ODE", additional_distance=0.0):
if format == "ODE": if format == "ODE":
import ode import ode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment