2

我使用 swig 包装 ac 函数以在 python 代码中使用时遇到属性错误。我在 chap 旁边还有其他功能可以正常工作,但是有些奇怪的原因这个不起作用:/

我正在尝试使用 CGAL 来确定所有粒子的凸包(第一章)。下面是 chap 函数和回溯:

std::vector<Vec2d> World::chap() const
{
    std::vector<Point_2> ch;
    std::vector<Point_2> points;
    std::vector<Vec2d> result;
    for(size_t i = 0, sz = particles.size(); i < sz; ++i)
    {
        points.push_back(Point_2(particles[i]->position.x, particles[i]->position.y));
    }
    CGAL::convex_hull_2(points.begin(), points.end(), std::back_inserter(ch));
    for(size_t i = 0, sz = ch.size(); i < sz; ++i)
    {
        result.push_back(Vec2d(ch[i].x(), ch[i].y()));
    }
    return result;
}

Traceback (most recent call last):
  File "keiro.py", line 64, in <module>
    if scenario.run():
  File "/Users/marcstrauss/Desktop/keiro/scenario.py", line 56, in run
    dt = self.world.advance()
  File "/Users/marcstrauss/Desktop/keiro/world.py", line 87, in advance
    view.add_ch(self.chap())
  File "/Users/marcstrauss/Desktop/keiro/fast/physics.py", line 312, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, World, name)
  File "/Users/marcstrauss/Desktop/keiro/fast/physics.py", line 34, in _swig_getattr
    raise AttributeError,name
AttributeError: chap
4

1 回答 1

2

功能是否公开?尝试调用声明为受保护的函数时出现相同的错误。 SWIG C++ 手册指出 Private 和 Protected 函数不会被包装

于 2012-01-19T15:25:25.757 回答