【发布时间】:2019-10-10 09:06:32
【问题描述】:
我必须序列化/反序列化一些精确的有理数(最好以人类可读的格式),使用 CGAL Exact_predicates_exact_constructions_kernel(Epeck 与惰性求值)计算。
我的想法是使用Cartesian_converter 将 Epeck 数转换为 Quotient 类型的精确数,并分别导出分子和分母:
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Cartesian_converter.h>
#include <CGAL/Quotient.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Simple_cartesian.h>
using QKernel = CGAL::Simple_cartesian<CGAL::Quotient<CGAL::MP_Float>>;
using Epeck = CGAL::Exact_predicates_exact_constructions_kernel;
// ...
CGAL::Point_2<Epeck> p(x, y);
CGAL::Cartesian_converter<Epeck, QKernel> to_qkernel;
CGAL::Point_2<QKernel> q = to_qkernel(p);
std::cout << q.x().numerator() << "/" << q.x().denominator() << " "
<< q.y().numerator() << "/" << q.y().denominator() << std::endl;
这不会编译,因为没有匹配的构造函数。似乎 Cartesian_converter 试图将 Epeck 数作为分子,由于 Epeck 数是 FieldType 而无法工作,而分子必须是 RingType。
/usr/local/include/CGAL/Quotient.h:97:35: error: no matching constructor for initialization of 'CGAL::Quotient<CGAL::MP_Float>::NT' (aka 'CGAL::MP_Float')
explicit Quotient(const T& n) : num(n), den(1) {}
^ ~
此外,这似乎不是最聪明的序列化方式(如果可行的话),因为分子和分母都不需要是整数。
问题:
有没有办法将多个类型Epeck::FT序列化为字符串n + "/" + d,其中n和d是整数?
【问题讨论】:
标签: c++ serialization type-conversion cgal