Optimizing some cubic beziers away

Bug #714717 reported by Jan Thor
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Medium
jazzynico
Scour
Fix Released
Medium
Unassigned
scour (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

When optimizing paths, scour discards commands which don’t advance the path, that is, which have a relative movement of 0,0. But this is wrong in the case of cubic beziers. For example, a path

    <path d="m 100,100 c 10,0 0,10 0,0 z"/>

is a raindrop-like figure, but scour only looks at the last 0,0, decides the "c" command to be superfluous and turns it into

    <path d="m100,100z"/>

which results in a different visual rendering. The right thing to do would be to look at all three coordinates of a cubic bezier command and only delete the command if all three of them are zero.

I encounter shapes like this quite often with vectorized scans of drawings I aggressively simplified within Inkscape (if someone is interested, I can include a test file, but I hope it should be clear what I’m talking about anyway).

Within cleanPath, and within the '# remove empty segments'-segment, the code

elif cmd == 'c':
    while i < len(data):
        if data[i+4] == data[i+5] == 0:
            del data[i:i+6]
            numPathSegmentsReduced += 1
        else:
            i += 6

should be replaced with

elif cmd == 'c':
    while i < len(data):
        if data[i] == data[i+1] == data[i+2] == data[i+3] == data[i+4] == data[i+5] == 0:
            del data[i:i+6]
            numPathSegmentsReduced += 1
        else:
            i += 6

Related branches

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

Hmm... yes, that was definitely an oversight when (0,0) removal was coded. Thanks for the bug report!

I just looked at the specification and saw that 'q' was also a curve command, so I edited your proposed fix to also require a (0,0) control point for that command. The fix is in trunk as revision 197.

Changed in scour:
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Louis Simard (louis-simard-deactivatedaccount) wrote :

In revision 201 there's also a change to how a unit test worked in relation to this bug. That unit test checked for a curve being removed, that had nonzero control points and zero movement.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package scour - 0.25+bzr207-1

---------------
scour (0.25+bzr207-1) unstable; urgency=low

  * New upstream bzr snapshot:
    - Add the option --no-renderer-workaround.
    - Fix gradient corruption. (LP: #702423)
    - Add option to only remove autogenerated id's. (LP: #492277)
    - Fix Windows line ending handling. (LP: #717826)
    - Fix occasional production of empty defs. (LP: #717254)
    - Remove more attributes with default values. (LP: #714731)
    - Fix wrong handling of file:// references. (LP: #708515)
    - Delete text attributes from groups with only non-text elements.
      (LP: #714727)
    - Remove unnecessary text-align properties from non-text elements.
      (LP: #714720)
    - Fix wrong optimization of 0-length Bézier curves. (LP: #714717)
    - Fix decimal number processing in rule_elliptical_arc(). (LP: #638764)
    - Fix transform matrix order. (LP: #722544)
  * Drop 01-bzr195.patch, upstream now.
  * debian/cmpsvg: Fix computation of difference to add up the absolute
    difference of each pixel.
  * debian/cmpsvg: Show percentages with three digits after comma.
  * debian/cmpsvg: Lower default treshold to 0.05%.
 -- Martin Pitt <email address hidden> Tue, 15 Mar 2011 09:28:45 +0100

Changed in scour (Ubuntu):
status: New → Fix Released
Revision history for this message
Louis Simard (louis-simard-deactivatedaccount) wrote :

This bug is fixed in release 0.26 of Scour.

Changed in scour:
status: Fix Committed → Fix Released
Revision history for this message
jazzynico (jazzynico) wrote :

Fixed in inkscape trunk revision 10785.

Changed in inkscape:
assignee: nobody → JazzyNico (jazzynico)
importance: Undecided → Medium
milestone: none → 0.49
status: New → Fix Committed
jazzynico (jazzynico)
Changed in inkscape:
status: Fix Committed → Fix Released
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.