Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def move_to_avg(objs, orientation):
"""
Move `objs` vertically/horizontally to their average x/y position.
"""
if orientation not in ("h", "v"):
raise ValueError("Orientation must be 'v' or 'h'")
if len(objs) == 0: return []
move_axis = "v" if orientation == "h" else "h"
attr = "top" if orientation == "h" else "x0"
values = list(map(itemgetter(attr), objs))
q = pow(10, utils.decimalize(values[0]).as_tuple().exponent)
avg = utils.decimalize(float(sum(values) / len(values)), q)
new_objs = [ utils.move_object(obj, move_axis, avg - obj[attr])
for obj in objs ]
return new_objs
def decimalize(self, x):
return utils.decimalize(x, self.pdf.precision)
def move_to_avg(objs, orientation):
"""
Move `objs` vertically/horizontally to their average x/y position.
"""
if orientation not in ("h", "v"):
raise ValueError("Orientation must be 'v' or 'h'")
if len(objs) == 0: return []
move_axis = "v" if orientation == "h" else "h"
attr = "top" if orientation == "h" else "x0"
values = list(map(itemgetter(attr), objs))
q = pow(10, utils.decimalize(values[0]).as_tuple().exponent)
avg = utils.decimalize(float(sum(values) / len(values)), q)
new_objs = [ utils.move_object(obj, move_axis, avg - obj[attr])
for obj in objs ]
return new_objs