Comment 9 for bug 638764

Revision history for this message
Louis Simard (louis-simard-deactivatedaccount) wrote :

We do want to use Decimal, for the --precision option.

From the Python docs [1]:

> The solution [to round the inputs to an arithmetic operation]
> is either to increase precision or to force rounding of inputs
> using the unary plus operation:

> >>> getcontext().prec = 3
> >>> +Decimal('1.23456789') # unary plus triggers rounding
> Decimal('1.23')

Decimal * 1 does like +Decimal, making sure that all coordinates are rounded to the precision specified on the command line before any operation is carried out on them. Otherwise, coordinates that have no operations carried out on them would be kept in their full precisions in the resulting file, despite the --precision option. This is a way to force at least one operation to be carried out on the numbers.

Also, if we were to use floats, coordinates could become monstrosities such as 3.240000001, which are definitely not an optimisation :)

As for * 1, there's another thing I used in svg_regex.py to create Decimal objects:

svg_regex.py:276: x = getcontext().create_decimal(token[1])
svg_regex.py:280: y = getcontext().create_decimal(token[1])

Maybe that would be more intuitive?