SVG/矢量图形对象布尔运算(并、交、减)

发布于 2024-10-03 16:17:56 字数 914 浏览 5 评论 0原文

我有 2D 闭合矢量路径,在 SVG 路径式语法 中指定 - 即这些路径包括直线和各种贝塞尔曲线。有没有像小而美的东西?允许对这些路径进行并集、交集和减法等布尔运算的离散库(最好是 C、Java 或 Ruby,但如果该库干净且易于使用,任何语言都可以)?

到目前为止我发现的包括:

  • 巨大且昂贵的商业矢量图形产品(例如 Autodesk AutoCAD 或 Adob​​e 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇纵 2024-10-10 16:17:56

也许我遗漏了一些东西,但是 java.awt.geom 包中的类不能满足您的需求吗?它们处理二维形状; 区域 类专门处理布尔运算:

Area 对象存储和操作二维空间封闭区域的与分辨率无关的描述。 Area 对象可以进行变换并可以执行各种操作
与其他区域对象组合时的构造区域几何 (CAG) 操作。 CAG运算包括面积加法、面积减法、交集和异或。

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.

月牙弯弯 2024-10-10 16:17:56

您可以 JavaScript ClipperAngus 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文