We introduce bindings that enable the convenient, efficient, and reliable use of software modules of CGAL (Computational Geometry Algorithm Library), which are written in C++, from within code written in Python. There are different tools that facilitate the creation of such bindings. We present a short study that compares three main tools, which leads to the tool of choice. The implementation of algorithms and data structures in computational geometry presents tremendous difficulties, such as obtaining robust software despite the use of (inexact) floating point arithmetic, found in standard hardware, and meticulous handling of all degenerate cases, which typically are in abundance. The code of CGAL extensively uses function and class templates in order to handle these difficulties, which implies that the programmer has to make many choices that are resolved during compile time (of the C++ modules). While bindings take effect at run time (of the Python code), the type of the C++ objects that are bound must be known when the bindings are generated, that is, when they are compiled. The types of the bound objects are instances (instantiated types) of C++ function and class templates. The number of object types that can potentially be bound, in implementation of generic computational-geometry algorithms, is enormous; thus, the generation of the bindings for all these types in advance is practically impossible. Often there are several choices to make, resulting in a prohibitively large number of combinations. We present a system that rapidly generates bindings for desired object types according to user prescriptions, which enables the convenient use of any subset of bound object types concurrently. The introduction of the bindings made them easily accessible to newcomers and practitioners in non-computing fields, as we report in the paper.
翻译:我们引入了一种接口绑定技术,使得用Python编写的代码能够方便、高效且可靠地调用以C++编写的CGAL(计算几何算法库)软件模块。现有多种工具可辅助创建此类绑定。本文通过对比三种主流工具,最终选定最优方案。计算几何中算法与数据结构的具体实现面临巨大挑战,例如在使用标准硬件提供的(非精确)浮点运算时需保证软件的鲁棒性,以及细致处理大量退化情形。CGAL代码广泛采用函数模板与类模板应对这些挑战,这意味着程序员需在编译阶段(针对C++模块)做出众多类型选择。尽管绑定在运行时(针对Python代码)生效,但被绑定的C++对象类型必须在绑定生成时(即编译期)明确确定。被绑定对象的类型是C++函数模板与类模板的实例化类型。在实现通用计算几何算法的过程中,可能被绑定的对象类型数量极其庞大,因此预先为所有类型生成绑定在实践中不可行。通常存在多种类型选择,导致组合数量多到难以承受。我们提出了一种系统,能够根据用户预设快速为目标对象类型生成绑定,从而支持并发使用任意子集的绑定对象类型。如文中所述,该绑定的推出使得非计算领域的初学者和从业者能够轻松使用CGAL库。