[ create a new paste ] login | about

Link: http://codepad.org/hZXqg9Kw    [ raw code | output | fork ]

Python, pasted on Jul 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def snap(origin, point, grid):
    def singlesnap( (o, p, d) ):
        p = p - o
        p_d = p % d
        if p_d < d / 2.:
            return p - p_d + o
        else:
            return p - p_d + o + d

    return map(singlesnap, zip(origin, point, grid))

origin = [0] * 3
point = [
  3,
  7,
  32,
]
grid = [5] * 3

print snap(origin, point, grid)


Output:
1
[5, 5, 30]


Create a new paste based on this one


Comments: