Archive for April, 2009

lib2geom is sweet stuff

Posted in Uncategorized on April 23rd, 2009 by ricardo – 2 Comments

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