math error in inkex.py function "uutounit"

Bug #1764557 reported by Johannes James
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Invalid
Undecided
Unassigned

Bug Description

Inkscape 0.91 r13725
Window10 64-bit

Just on naive use, it looks like the inkex.py function "uutounit()" defined in line 359 of the inkex.py which came with inkscape 0.91 might have a simple math error:
Seems that it should be:
    def uutounit(self, val, unit):
        return val * (self.__uuconv[unit] / self.__uuconv[self.getDocumentUnit()])

instead of:
    def uutounit(self, val, unit):
        return val / (self.__uuconv[unit] / self.__uuconv[self.getDocumentUnit()])

(difference being only the multiplication instead of division...)

Given code in extension:

#start of code
import inkex
#SVG element generation routine
def draw_SVG_square((w,h), (x,y), parent, self):

    style = { 'stroke' : 'none',
                'stroke-width' : '1',
                'fill' : '#000000'
            }

    attribs = {
        'style' : simplestyle.formatStyle(style),
        'height' : str( inkex.Effect.uutounit(self, h, 'mm') ),
        'width' : str(inkex.Effect.uutounit(self, w, 'mm')),
        'x' : str(x),
        'y' : str(y)
            }
    circ = inkex.etree.SubElement(parent, inkex.addNS('rect','svg'), attribs )

draw_SVG_square((10,10), (0,0), parent, self)
# end of code

Expected: a square 10mm per side if documents units are in px.
Observed: a square of 0.796 mm.
confirmation: changing the inkex.py function as above results in the expected 10.0mm square. caveat: I am not a good coder though.

Revision history for this message
Qantas94Heavy (qantas94heavy) wrote :

Hi there, I don't think this is a bug.

uutounit is meant to convert document units to your chosen unit. So if the document unit was inches, self.uutounit(10, 'mm') would return 254, which is the equivalent size in mm.

Please let me know if I am mistaken or if you have any other questions. Thank you!

Changed in inkscape:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.