Commit e184a5f7 authored by sumpfralle's avatar sumpfralle

fixed comparison of Points for "near" points (due to float inaccuracies)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@417 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2de4f570
...@@ -22,6 +22,9 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,6 +22,9 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
import math import math
def _is_near(x, y):
return abs(x - y) < 1e-6
class Point: class Point:
id=0 id=0
...@@ -41,20 +44,15 @@ class Point: ...@@ -41,20 +44,15 @@ class Point:
Otherwise the result is based on the individual x/y/z comparisons. Otherwise the result is based on the individual x/y/z comparisons.
""" """
if self.__class__ == other.__class__: if self.__class__ == other.__class__:
if (self.x == other.x) and (self.y == other.y) and (self.z == other.z): if (_is_near(self.x, other.x)) and (_is_near(self.y, other.y)) \
and (_is_near(self.z, other.z)):
return 0 return 0
elif self.x < other.x: elif not _is_near(self.x, other.x):
return -1 return cmp(self.x, other.x)
elif self.x > other.x: elif not _is_near(self.y, other.y):
return 1 return cmp(self.y, other.y)
elif self.y < other.y:
return -1
elif self.y > other.y:
return 1
elif self.z < other.z:
return -1
else: else:
return 1 return cmp(self.z, other.z)
else: else:
return cmp(str(self), str(other)) return cmp(str(self), str(other))
......
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