Skip to content

Instantly share code, notes, and snippets.

@kmill
Created June 6, 2015 22:46
Show Gist options
  • Save kmill/3d076b864a8fec1517af to your computer and use it in GitHub Desktop.
Save kmill/3d076b864a8fec1517af to your computer and use it in GitHub Desktop.
def quantize(w, x, y, z, n) :
if z == None :
z = 1.0 - w - x - y
n = int(n)
v = [w, x, y, z]
vn = [a * n for a in v]
vni = [int(a) for a in vn]
vnf = [a - ai for a, ai in zip(vn, vni)]
cutoff = sum(vnf) / 4
def cround(xi, xf) :
return float(xi + (0 if xf < cutoff else 1)) / n
return [cround(ai, af) for ai, af in zip(vni, vnf)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment