Skip to content

Commit

Permalink
Add option for rounding to set number of decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeszaros committed Aug 14, 2020
1 parent c84731e commit 40c7c42
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions scour/scour.py
Original file line number Diff line number Diff line change
Expand Up @@ -2821,8 +2821,8 @@ def parseListOfPoints(s):
i = 0
while i < len(nums):
try:
nums[i] = getcontext().create_decimal(nums[i])
nums[i + 1] = getcontext().create_decimal(nums[i + 1])
nums[i] = getcontext().create_decimal(nums[i]).quantize(roundingQuantum)
nums[i + 1] = getcontext().create_decimal(nums[i + 1]).quantize(roundingQuantum)
except InvalidOperation: # one of the lengths had a unit or is an invalid number
return []

Expand Down Expand Up @@ -3641,8 +3641,10 @@ def scourString(in_string, options=None):
# to minimize errors
global scouringContext
global scouringContextC # even more reduced precision for control points
global roundingQuantum
scouringContext = Context(prec=options.digits)
scouringContextC = Context(prec=options.cdigits)
roundingQuantum = Decimal(10) ** (-options.rounding)

# globals for tracking statistics
# TODO: get rid of these globals...
Expand Down Expand Up @@ -3976,6 +3978,9 @@ def format_usage(self, usage):
action="store", type=int, dest="cdigits", default=-1, metavar="NUM",
help="set number of significant digits for control points "
"(default: same as '--set-precision')")
_option_group_optimization.add_option("--set-rounding",
action="store", type=int, dest="rounding", default=9, metavar="NUM",
help="set number of digits after decimal point (default: %default)")
_option_group_optimization.add_option("--disable-simplify-colors",
action="store_false", dest="simple_colors", default=True,
help="won't convert colors to #RRGGBB format")
Expand Down

0 comments on commit 40c7c42

Please sign in to comment.