Add utility away_from_zero_round and use it for LESS round()
Also _ophsl should use it when running unter Py3k (instead of convergent_round).
This commit is contained in:
@@ -364,5 +364,5 @@ class Color():
|
||||
hls = list(self._hextohls(color))
|
||||
hls[idx] = self._clamp(getattr(hls[idx], op)(diff / 100.0))
|
||||
rgb = colorsys.hls_to_rgb(*hls)
|
||||
color = (utility.convergent_round(c * 255) for c in rgb)
|
||||
color = (utility.away_from_zero_round(c * 255) for c in rgb)
|
||||
return self._rgbatohex(color)
|
||||
|
||||
@@ -13,6 +13,7 @@ from __future__ import print_function
|
||||
import collections
|
||||
import math
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def flatten(lst):
|
||||
@@ -246,6 +247,18 @@ def split_unit(value):
|
||||
return r.groups() if r else ('', '')
|
||||
|
||||
|
||||
def away_from_zero_round(value, ndigits=0):
|
||||
"""Round half-way away from zero.
|
||||
|
||||
Python2's round() method.
|
||||
"""
|
||||
if sys.version_info[0] >= 3:
|
||||
p = 10 ** ndigits
|
||||
return float(math.floor((value * p) + math.copysign(0.5, value))) / p
|
||||
else:
|
||||
return round(value, ndigits)
|
||||
|
||||
|
||||
def convergent_round(value, ndigits=0):
|
||||
"""Convergent rounding.
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ class Call(Node):
|
||||
str
|
||||
"""
|
||||
n, u = utility.analyze_number(value)
|
||||
return utility.with_unit(int(round(float(n))), u)
|
||||
return utility.with_unit(int(utility.away_from_zero_round(float(n))), u)
|
||||
|
||||
def ceil(self, value, *args):
|
||||
""" Ceil number
|
||||
|
||||
Reference in New Issue
Block a user