pylada/pylada-light

Incorrect original norm in into_voronoi

mdavezac opened this issue · 0 comments

Hi Mayeul,

I was using the into_voronoi routine in another context, and found an error.

def into_voronoi(position, cell, inverse=None):

    from numpy import dot, floor
    from numpy.linalg import inv, norm
    if inverse is None:
        inverse = inv(cell)
    center = dot(inverse, position)
    center -= floor(center)
    result = center
    n = norm(center)
    for i in range(-1, 2, 1):
        for j in range(-1, 2, 1):
            for k in range(-1, 2, 1):
                translated = [i, j, k] + center
                n2 = norm(dot(cell, translated))
                if n2 < n:
                    n = n2
                    result = translated
    return dot(cell, result)


n = norm(center) should be  n = norm(dot(cell,center))

In analogy to n2 = norm(dot(cell, translated))
to which it is later compared.