SVG / vector graphical objects boolean operations

2019-02-02 00:38发布

I have 2D closed vector paths, specified in SVG paths-like syntax - i.e. these paths include straight lines and various Bezier curves. Is there anything like a small, nice & discrete library (preferably in C, Java or Ruby, but any language will do if this library is clean and easy to use) that allows to do boolean operations like union, intersection and subtraction with these paths?

What I've found so far includes:

  • Huge and pricey commercial vector graphic products (such as Autodesk AutoCAD or Adobe Illustrator) that can be called using some sort of API or scripted to do boolean 2D paths operations - which is clearly an overkill for my purposes.
  • Inkscape developed in-house lib2geom library which lacks documentation, bindings, has some compilation issues, seems to be used in no projects besides Inkscape itself and looks fairly complex.
  • CGAL is a huge and pretty complex computational geometry library, that works in pretty weird object space (i.e. you have crazy mix of templates, imperative style functions to do operations on these templated data structures, etc, etc), and doesn't seem to have sane bindings to other languages beside C++. Python bindings to CGAL seem to be abandoned and don't look very friendly to me.
  • JTS seems to be GIS-centred and deals only with straight lines, while I need to deal with SVG-like Bezier curves.

So, the question is, is there are any other small, nice & easy libraries floating around to deal with boolean operations on SVG-like paths?

2条回答
看我几分像从前
2楼-- · 2019-02-02 00:46

Perhaps I'm missing something, but wouldn't the classes in the java.awt.geom package suit your needs? They deal with two-dimensional shapes; the Area class deals specifically with boolean operations:

An Area object stores and manipulates a resolution-independent description of an enclosed area of 2-dimensional space. Area objects can be transformed and can perform various Constructive Area Geometry (CAG) operations when combined with other Area objects. The CAG operations include area addition, subtraction, intersection, and exclusive or.

查看更多
小情绪 Triste *
3楼-- · 2019-02-02 00:59

You can JavaScript Clipper ,a port of Angus Johnson's Clipper (written in Delphi, C++, C# and Python), which in turn is based on Bala R. Vatti's clipping algorithm. It is able to handle all polygon cases, including the self-intersecting ones.

Keep in mind that the lib takes only polygons so any curves need to be polygonized first

查看更多
登录 后发表回答