[metapost] Trying to figure out MPLib

Shriramana Sharma samjnaa at gmail.com
Fri Aug 3 16:27:42 CEST 2012


On Fri, Aug 3, 2012 at 6:39 PM,  <mskala at ansuz.sooke.bc.ca> wrote:
>
> The algorithm is described reasonably well in a few pages of the MetaFont
> book, and (I would hope) also in Hobby's original papers.  Why not
> implement it yourself?  I suspect that might be less work than trimming
> all the TeX dependencies off of MetaPost.

Hi thanks -- that's one of the approaches I'm considering. But I'm
wondering whether I have the mathematical knowledge to understand and
implement the algorithm properly. (Who knows, maybe I could surprise
myself!)

I also need to produce PS output (the other thing I'm using MP for) to
import glyphs into a font -- but probably I can use Cairo for that.

So basically if there were a simple C library which would get MP style
input for a path -- at least for the continuous curve parts of it not
including straight lines (which are not an issue and are split up
internally by MF/MP anyway) -- and write to a linked list of a struct
with node, ctrl, ctrl, node or such -- it could be used from virtually
any programming language (since most other languages provide
interfaces to C).

FWIW http://tex.stackexchange.com/questions/54771/curve-through-a-sequence-of-points-with-metapost-and-tikz
has an incomplete python implementation of the algorithm by one J L
Diaz (perhaps s/he is on this list?).

[BTW this is not directly relevant to the thread subject, but I have
to say that I completely agree with the above J L Diaz when s/he says
"The algorithm is used in METAFONT and MetaPost, but the source code
of these programs is hard to read. I tried to implement it in a more
modern way, which makes the algorithm more understandandable and
perhaps portable to other languages".

If readable source code is what literate programming means, I daresay
it can be done in regular C/C++ without the need for CWEB or such
which makes source code re-use very difficult in non-CWEB projects
(which are by far the greater in number).

IMHO well-formed variable names and such, with appropriate explanatory
comments for sections of code in /**/ or such would be enough for
readable source-code. User-visible documentation can be produced using
the same kind of comments using tools like doxygen -- there are lots
of OSS projects out there which produce useful source code and
documentation this way.

If MP had been implemented this way, it would be relatively much
easier for people like me or Diaz above, to extract the Hobby
algorithm (and other useful stuff) from the MPLib sources making it a
more useful library in the overall OSS world. Just my humble
thoughts...]

-- 
Shriramana Sharma


More information about the metapost mailing list