jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.58k stars 505 forks source link

fix(svg-deserializer): fix quadratic bezier paths #1228

Closed platypii closed 1 year ago

platypii commented 1 year ago

Fix a bunch of bugs in the svg-deserializer. Specifically we were not computing quadratic bezier paths correctly.

To convert a quadratic bezier curve to a cubic curve requires generating the following control points:

C0 = Q0
C1 = Q0 + (2/3) (Q1 - Q0)
C2 = Q2 + (2/3) (Q1 - Q2)
C3 = Q2

But the code was previously doing:

C0 = Q0
C1 = Q1
C2 = Q1
C3 = Q2

Visually this means we were using the green dot twice, instead of computing the red dots:

quad2cubic

Fixes #1222

33

Also found a bug where we were not converting svg unit for [cx, cy] on the svg t command.

Cleaned up the code style to make more readable. Changes to functionality were only in q, Q, t, and T svg commands.

All Submissions:

z3dev commented 1 year ago

@platypii these changes look really nice.

just wondering... shouldn't we correct shapesMapJscad.js as well?

platypii commented 1 year ago

@z3dev I updated shapesMapJscad good catch