danmarshall/svg-path-outline

run MakerJS directly

sysmaya opened this issue · 1 comments

Reviewing your code in search of improving speed..
And I find that it is only a wrapper that calls the expandPaths() function of MakerJS

But if I run the same code using MakerJS natively, the speed improves X10

You can run the code here:
https://maker.js.org/docs/advanced-drawing/

But anyway the result is useless. the result is a group, with hundreds of PATH segments forming the span.

var m = require('makerjs');
var pathData = "M305.8 54.5 303.3 41.3 302.3 41.3 300 54.5Q299.8 56.2 287.4 56.2A16.6 16.6 0 01282.9 55.8 2.5 2.5 0 01281.3 54.5Q267.9 21.5 267.9 19.8 267.9 18.1 273.1 16.3A30.2 30.2 0 01283.2 14.4Q289.4 14.4 289.6 17.7L292 37.5 292.9 37.5 293.8 21.5A4.6 4.6 0 01297.4 18.4 20.3 20.3 0 01304.7 17 13 13 0 01310.2 17.9 2.8 2.8 0 01312.1 20.1L312.9 37.5 313.7 37.5 316.1 19Q316.3 17.2 320.9 15.8A28.7 28.7 0 01329.1 14.4 12.6 12.6 0 01334.7 15.4 4.6 4.6 0 01338 19.2 888.9 888.9 0 01331.5 36.7 935.6 935.6 0 01324.7 54.5Q323.8 56.2 315 56.2 306.1 56.2 305.8 54.5ZM167.6 32.3 167.6 54.5Q167.6 55.2 163.5 55.7A74.6 74.6 0 01155.1 56.2 24 24 0 01149.4 55.8 1.5 1.5 0 01148.2 54.5L148.2 31.6A22.1 22.1 0 00147.9 27.3 88.3 88.3 0 00147.5 25.5 1.8 1.8 0 00145.7 24.1 1.8 1.8 0 00143.6 26.1L143.6 54.5Q143.6 55.2 139.6 55.7A73.7 73.7 0 01131.1 56.2 24.6 24.6 0 01125.5 55.8 1.5 1.5 0 01124.2 54.5L124.2 19Q124.2 17.4 128.3 15.9A25.3 25.3 0 01137.1 14.4Q141.7 14.4 142.3 17.1L142.9 20.3 143.4 20.3A11.6 11.6 0 01150.6 14.4 15.5 15.5 0 01155.2 13.8 10.4 10.4 0 01165.1 18.1 29.3 29.3 0 01167.6 32.3ZM0 54.1 0 7.8Q0 5.9 4.7 5.1A74 74 0 0116.6 4.3 723.9 723.9 0 0126 4.4 88.1 88.1 0 0131 4.6 22.5 22.5 0 0135.5 5.3 50.7 50.7 0 0139.3 6.6 8.3 8.3 0 0142.5 8.7 20.6 20.6 0 0144.7 11.7 16.6 16.6 0 0146.7 20.5 21.9 21.9 0 0144.7 30.2 14.1 14.1 0 0139.7 36.1Q48 49.1 48 52.7 48 56.2 33.8 56.2A29.9 29.9 0 0128.1 55.8 2.5 2.5 0 0126.1 54.2L21.4 39.4 20.2 39.3 20.2 54.1Q20.2 55 15.8 55.6A67.8 67.8 0 016.9 56.2 19.4 19.4 0 011.3 55.7 1.7 1.7 0 010 54.1ZM72.1 30.8 74.4 30.8A4.5 4.5 0 0072.4 26.6 5.4 5.4 0 0069.8 26.1 12.4 12.4 0 0065.6 27 27.3 27.3 0 0061.4 28.9 6 6 0 0159.2 29.9 6.3 6.3 0 0155.7 26.5 11.7 11.7 0 0153.4 20.3 4.5 4.5 0 0156.1 17.8 31.9 31.9 0 0163.6 15 37.7 37.7 0 0173.1 13.8 36.5 36.5 0 0181 14.5 23.8 23.8 0 0186.5 16.4 11.1 11.1 0 0190.1 19.2 19.8 19.8 0 0192.3 22.5 12.2 12.2 0 0193.5 26.2 36 36 0 0194 32.8L94 54.5Q94 55.2 90.1 55.7A63.2 63.2 0 0182.5 56.2 33.5 33.5 0 0177.6 56 2.5 2.5 0 0176.2 55.5 2.6 2.6 0 0175.9 54.5L75.3 50.3 74.7 50.3A8.9 8.9 0 0164.9 56.8 15.7 15.7 0 0154.6 53.7 10.6 10.6 0 0151.9 49.9 14.5 14.5 0 0150.8 44 10.7 10.7 0 0152.5 38.1 11.9 11.9 0 0156.4 34.2 22.3 22.3 0 0161.8 32 40.6 40.6 0 0172.1 30.8ZM172.7 52.4 172.7 6.8Q172.7 5.2 176.9 3.7A26.4 26.4 0 01185.8 2.2Q192.2 2.2 192.2 5.5L192.2 13.6 191.4 18.6 192 18.6A7.8 7.8 0 01193.6 17 14.5 14.5 0 01196.1 15.4 14.8 14.8 0 01203 13.8 15.2 15.2 0 01209.1 14.7 9.8 9.8 0 01212.6 17.3 11.5 11.5 0 01214.7 21.2 32.7 32.7 0 01216.1 31.4 41.1 41.1 0 01213.8 47 13.9 13.9 0 01206.3 54.6 38.1 38.1 0 01191.7 56.8 66.1 66.1 0 01176.6 55.5Q172.7 54.5 172.7 52.4ZM233.6 55.9A40.1 40.1 0 00242.9 56.8 24.1 24.1 0 00259.6 51.3 20.9 20.9 0 00265.8 34.9 31.5 31.5 0 00264.5 25.5 17.4 17.4 0 00261.4 19.4 13.1 13.1 0 00256.4 15.9 24.4 24.4 0 00250.2 14.2 57.1 57.1 0 00242.9 13.8 26.7 26.7 0 00226.7 18.4Q220 23.3 220 34.9 220 47.8 226.6 52.6A19.1 19.1 0 00233.6 55.9ZM118.8 19 118.8 54.5Q118.8 55.2 114.7 55.7A75.6 75.6 0 01106.2 56.2 24 24 0 01100.5 55.8 1.5 1.5 0 0199.3 54.5L99.3 20.3Q99.3 18.7 103.4 17.1A24.8 24.8 0 01112.2 15.6Q118.8 15.6 118.8 19ZM116.5 1.4A16.3 16.3 0 00109 0Q99 0 99 6.5 99 13 109.1 13 119.2 13 119.2 6.5A5.2 5.2 0 00116.5 1.4ZM192.1 46.2 194.3 46.2Q196.6 46.2 196.6 35.2 196.6 24.1 194.3 24.1L192.1 24.1 192.1 46.2ZM240.4 42.8Q240.4 42.8 240.7 44.1A3.3 3.3 0 00241.5 45.9 2 2 0 00242.9 46.4 2 2 0 00244.3 45.9 6.8 6.8 0 00245.3 42.8 37.7 37.7 0 00245.8 36.3 76.7 76.7 0 00245.6 30.2 27 27 0 00245.2 26.9 5.3 5.3 0 00244.5 25.1 1.9 1.9 0 00243 24.2 2.1 2.1 0 00241.5 24.8 7 7 0 00240.4 27.9 42 42 0 00239.9 35.4 41.4 41.4 0 00240.4 42.8ZM20.2 28.2 22 28.2Q26.2 28.2 26.2 21.8A7.5 7.5 0 0025.1 17.1 3.3 3.3 0 0022.5 15.7L20.2 15.7 20.2 28.2ZM74.5 44.9 74.5 36.5A3.6 3.6 0 0071.5 38 6 6 0 0070.3 41.6Q70.3 46.4 72.5 46.4A2.2 2.2 0 0074 45.9 1.4 1.4 0 0074.5 44.9Z";
var rainbow = m.importer.fromSVGPathData(pathData);
var expanded = m.model.expandPaths(rainbow, 10);

var model = {
    models: {
        rainbow: rainbow,
        expanded: expanded
    }
};
var svg = m.exporter.toSVG(model);
document.write(svg);

Hello, the boolean combination algorithm in Maker.js is unoptimized and definitely has a few bugs. You may need to find strategies to break up your path into smaller chunks and perhaps do some caching.