btel / svg_utils

Python tools to create and manipulate SVG files
MIT License
308 stars 86 forks source link

Figure.Tile() throws TypeError: unsupported operand type(s) for /: 'Unit' and 'int' #20

Closed DizietAsahi closed 6 years ago

DizietAsahi commented 7 years ago

See Stack Overflow post by user Allan for a complete description: https://stackoverflow.com/questions/45850144/is-there-a-bug-in-svgutils-compose-module-regarding-the-arrangement-of-figures/45863869#45863869

Here is a one-liner that reproduces the problem:

from svgutils import *
Figure( "21cm", "29.7cm",
    Text("A"),
    Text("B"),
).tile(1,2)

I propose the following fix in function svgutils.compose.Figure.tile():

dx = self.width.to('px').value/ncols
dy = self.height.to('px').value/nrows
btel commented 6 years ago

The problem was specific to Python 3. Unit class already implemented a division operator (div), but it was not triggered in Python 3, which uses a different special function (truediv). This should be now solved in master. Thanks for reporting.