Detect and create <circle> elements from <path d="cubic spline of circle">

Registered by Johan Sundström

It would be really sweet if Scour could produce <circle cx="0.330689" cy="0.330689" r="0.330689"/> from input like <path d="M0.330689 0c-0.182634,0 -0.330689,0.148055 -0.330689,0.330689 0,0.182638 0.148055,0.330689 0.330689,0.330689 0.182634,0 0.330689,-0.148051 0.330689,-0.330689 0,-0.182634 -0.148055,-0.330689 -0.330689,-0.330689z">, the typical basic spline approximation produced by many editors (here: Corel Draw).

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

Sorry if that got a bit unreadable. Attempting to add unsignificant whitespace for readability:

<path d="M 0.330689 0
         c -0.182634, 0
           -0.330689, 0.148055
           -0.330689, 0.330689

                   0, 0.182638
            0.148055, 0.330689
            0.330689, 0.330689

            0.182634, 0
            0.330689,-0.148051
            0.330689,-0.330689

                   0,-0.182634
           -0.148055,-0.330689
           -0.330689,-0.330689
         z"/>

This example from https://github.com/johan/svg-cleanups/blob/1e3990e09703819b99d32cc9f9f67df988aeaf82/pp/PP-logo-light.svg (the third element from the end). In my cleaned-up version at https://github.com/johan/svg-cleanups/blob/master/pp/PP-logo-light.svg it's the first tag (I also multiplied all values by a million to cut down on some excess periods, but that's unrelated to this blueprint).

Another related possible optimization: detecting consecutive cubic spline segments of a path that could be shortened to a single arc commands goes half way, while also arguably finding more things to optimize in general.

In the example, the relation between 0.182634 and 0.330689 is (Math.sqrt(2)-1)*4/3 (or anything up to 0.000501 less – for more details on the math, see http://www.tinaja.com/glib/ellipse4.pdf), and the other magic number (0.148051) is 0.330689 - 0.182638. In other words, setting X=Math.sqrt(2)-1)*4/3 and r=0.330689, we get the following pattern to detect:

<path d="M  r        0
         c -r*X    , 0
           -r      , r*(1-x)
           -r      , r

                  0, r*X
            r*(1-x), r
            r      , r

            r*X    , 0
            r      ,-r*(1-x)
            r      ,-r

                  0,-r*X
           -r*(1-x),-r
           -r      ,-r
         z"/>

...and optimize to

<circle cx="r" cy="r" r="r"/>

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.