Commit 7259d2f0 authored by Lars Kruse's avatar Lars Kruse

allow point comparison for selected axes

parent 6e4610d2
...@@ -23,8 +23,6 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,8 +23,6 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.utils import epsilon, sqrt, number from pycam.Geometry.utils import epsilon, sqrt, number
def _is_near_float(x, y):
return abs(x - y) < epsilon
def pnorm(a): def pnorm(a):
return sqrt(pdot(a,a)) return sqrt(pdot(a,a))
...@@ -40,22 +38,20 @@ def pdist_sq(a, b, axes=None): ...@@ -40,22 +38,20 @@ def pdist_sq(a, b, axes=None):
axes = (0, 1, 2) axes = (0, 1, 2)
return sum([(a[index] - b[index]) ** 2 for index in axes]) return sum([(a[index] - b[index]) ** 2 for index in axes])
def pnear(a, b): def pnear(a, b, axes=None):
return _is_near_float(a[0], b[0]) and _is_near_float(a[1], b[1]) and \ return pcmp(a, b, axes=axes) == 0
_is_near_float(a[2], b[2])
def pcmp(a, b): def pcmp(a, b, axes=None):
""" Two points are equal if all dimensions are identical. """ Two points are equal if all dimensions are identical.
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 pnear(a, b): if axes is None:
return 0 axes = (0, 1, 2)
elif not _is_near(a[0], b[0]): for axis in axes:
return cmp(a[0], b[0]) if abs(a[axis] - b[axis]) > epsilon:
elif not _is_near(a[1], b[1]): return cmp(a[axis], b[axis])
return cmp(a[1], b[1]) # both points are at the same position
else: return 0
return cmp(a[2], b[2])
def ptransform_by_matrix(a, matrix): def ptransform_by_matrix(a, matrix):
if len(a) > 3: if len(a) > 3:
......
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