SVG/矢量图形对象布尔运算(并、交、减)
我有 2D 闭合矢量路径,在 SVG 路径式语法 中指定 - 即这些路径包括直线和各种贝塞尔曲线。有没有像小而美的东西?允许对这些路径进行并集、交集和减法等布尔运算的离散库(最好是 C、Java 或 Ruby,但如果该库干净且易于使用,任何语言都可以)?
到目前为止我发现的包括:
- 巨大且昂贵的商业矢量图形产品(例如 Autodesk AutoCAD 或 Adobe Illustrator),可以使用某种 API 调用或编写脚本来执行布尔 2D 路径操作 - 这对我来说显然是一种杀伤力。目的。
- Inkscape 开发的内部 lib2geom 库缺乏文档、绑定,存在一些编译问题,似乎除了 Inkscape 本身之外没有在任何项目中使用,并且看起来相当复杂。
- CGAL 是一个巨大且相当复杂的计算几何库,它在非常奇怪的对象空间中工作(即你有疯狂的混合)模板、对这些模板化数据结构执行操作的命令式函数等),并且似乎没有与 C++ 之外的其他语言的合理绑定。 Python 与 CGAL 的绑定似乎被放弃了,对我来说看起来不太友好。
- JTS 似乎以 GIS 为中心,只处理直线,而我需要处理具有类似 SVG 的贝塞尔曲线。
所以,问题是,还有其他小而漂亮的吗?是否有简单的库可以处理类似 SVG 路径上的布尔运算?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许我遗漏了一些东西,但是
java.awt.geom
包中的类不能满足您的需求吗?它们处理二维形状;区域
类专门处理布尔运算: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; theArea
class deals specifically with boolean operations:您可以 JavaScript Clipper ,Angus Johnson 的 Clipper(用 Delphi、C++、C# 和 Python 编写),它又基于 Bala R. Vatti 的裁剪算法。它能够处理所有多边形情况,包括自相交的情况。
请记住,该库只需要多边形,因此任何曲线都需要多边形化首先
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