dbuenzli / vg

Declarative 2D vector graphics for OCaml
http://erratique.ch/software/vg
ISC License
86 stars 12 forks source link

[Draft] Adding support for smooth paths #34

Closed francoisthire closed 6 months ago

francoisthire commented 6 months ago

Solve #33

Context

This PR adds two functions smooth_ccurve and smooth_qcurve which allow to define smooth curves. One of the control points is defined depending on the previous curve.

The function smooth_ccurve corresponds to s and S SVG path commands, while smooth_qcurve corresponds to t and T SVG path commands. More details here

TODO:

Questions to the reviewers

dbuenzli commented 6 months ago

[ ] Check the PR compiles correctly (I did not find brzo on opam. I will pin it later)

The official build system is still topkg so simply opam install topkg-care and do topkg build.

dbuenzli commented 6 months ago
  • Which kind of test should be added?

You can add a sample image in the database, named path-smooth, that shows use of the combinators see for example path-cubics (src).

You can then have a look at the results by running for example rsvg.native. See here on how to build the tests. One day I hope to have a raster renderer and expect test the renders with pixeldrift. But meanwhile that should do.

francoisthire commented 6 months ago

I followed your instructions:

Here is the result:

screen_004

The implicit control point is colored in red.

francoisthire commented 6 months ago

I have updated the CHANGES file. Let me know if there is anything more that I can do.

dbuenzli commented 6 months ago

Thanks!

I squashed your patches into 3b3cea5 and 2d77ab2 and cosmetically massaged them in 33e1952.

Using trigonometry to compute point reflections felt rather heavy weight (and more expensive) so in 1e690d3 I replaced computations by simple linear algrebra following this diagram:

reflect

francoisthire commented 6 months ago

Perfect, thanks!