lib2geom is sweet stuff
A few days ago i heard that [lib2geom][lib2geom] came out with a new version.
The best news are that there are functional Python bindings available!
Lib2geom is an awesome library to deal with vector mathy stuff — points,
beziers, arcs, boolean operations and all those convoluted things that we take
from granted in WYSIWYG software, but are remarkably absent from the Python
world. Well, no more, now that py2geom is around!
For installing it on Debian-based systems, one just needs to track the dependencies:
sudo aptitude install libcairo2-dev cmake make libboost-dev libgsl0-dev
This will pull a *lot* of packages because you’re using development libraries.
But it’s worth it :) After that’s done, get the source from the SVN repository:
svn co https://lib2geom.svn.sourceforge.net/svnroot/lib2geom/lib2geom/trunk lib2geom
Now head to the lib2geom/src directory and type
cmake -i
Say No to advanced options, and then say yes to the ‘Python’ and ‘Shared’
options, which should be the first two that you’ll get asked. After that, just
hit enter to the other options and once cmake is done, do
make
My machine complained, giving out a lot of warnings on cmake, and make
eventually borked with some nagging about a missing ‘glib.h’.
After calling for help at the 2geom channel on Jabber, njh gave the great
advice to run
sudo apt-get build-dep inkscape
which will install all libs necessary for compiling Inkscape and thus 2geom
(and there’s an awful lot of them).
After make was finally done, just do the magic
sudo make install
To make sure stuff is in the right place, run python and try:
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import py2geom
>>>
If you don’t get an ImportError, perfect! Trying the example from the
[Inkscape wiki][inkscapeexample] shows the neat stuff 2geom can do:
>>> import py2geom as geom
>>> a = geom.Point(1,2)
>>> b = geom.Point(31,2)
>>> print a, b
(1.0, 2.0) (31.0, 2.0)
>>> print “Dot product:”, geom.dot(a,b)
Dot product: 35.0
>>> print “a times 2:”, a * 2
a times 2: (2.0, 4.0)
>>> print “Equal? (0 = no, 1 = yes):”, a == b
Equal? (0 = no, 1 = yes): 0
>>>
There’s still some work to be done on the Python bindings (for example,
there’s still no binding to the Path object), but the future looks bright for
the vector scripting world (:
[lib2geom]: http://lib2geom.sourceforge.net
[inkscapeexample]: http://wiki.inkscape.org/wiki/index.php/Lib2geom_py2geom
Nice work! Everything seems to be working, but the python bindings have ended up in Python 2.6 and don’t seem to be in my import path (importing only works from the actual site-packages folder). Any suggestions (this is Ubu Jaunty).
Have you found anything resembling an API reference, or is this a treasure hunt?
RS
Hmm, i got it working fine under both Python 2.5 and 2.6. I don’t know if 2.6 modules are compatible with 2.5, but doesn’t hurt to try: the py2geom stuff should have landed in your /usr/local/lib/python2.6/dist-packages folder. Just copy it over to a dir in your Python 2.5 sys.path (like site-packages), and you should be set.
Regarding the API reference, there’s not a lot of info around, but you can find doxygen-based docs in the 2geom source, as well as a LaTeX manual that can be compiled to PDF. I’d say the best way would be to check out the lib2geom Jabber channel over at conference.gristle.org and voicing your questions — that’s what i’ve been doing so far, the people over there are unbelievably friendly and helpful.
Also, i’ve found most of the API using ipython and command completion, so i’d suggest tinkering away :)
Nice post. I find out something tougher on distinct blogs each day. It will always be stimulating you just read content via other copy writers and practice a little from their particular store. I’d prefer to use some while using content on my weblog whether you don’t head. Natually I’ll offer you a link on your own web web site. Thanks with regard to sharing.