diff --git a/python/src/core/geometry/codac_py_geometry.cpp b/python/src/core/geometry/codac_py_geometry.cpp index 2d2ed71f1..742d9b814 100644 --- a/python/src/core/geometry/codac_py_geometry.cpp +++ b/python/src/core/geometry/codac_py_geometry.cpp @@ -17,6 +17,7 @@ #include #include "../contractors/static/codac_py_Ctc.h" #include "../separators/codac_py_Sep.h" +#include "codac_Polygon.h" // Generated file from Doxygen XML (doxygen2docstring.py): #include "codac_py_CtcSegment_docs.h" @@ -28,6 +29,34 @@ namespace py = pybind11; using namespace ibex; using namespace codac; +Polygon* create_polygon_from_pylist(const vector& lst) +{ + vector v_pts; + + if(lst.size() < 1) + throw invalid_argument("size of the input list is 0"); + + //double (*tmp)[2] = new double[lst.size()][2]; + for(size_t i = 0; i < lst.size(); i++) + { + if(lst[i].size() != 2) + { + //delete[] tmp; + throw invalid_argument("sub list must contain only two elements"); + } + + //tmp[i][0] = lst[i][0].cast(); + //tmp[i][1] = lst[i][1].cast(); + v_pts.push_back({ lst[i][0].cast(), lst[i][1].cast() }); + } + + //IntervalVector *instance = new IntervalVector(lst.size(), tmp); + //delete[] tmp; + //return instance; + return new Polygon(v_pts); + // todo: manage delete +} + SepPolygon* SepPolygonFromList(std::vector< std::array >& lst){ size_t n = lst.size(); std::vector ax(n), ay(n),bx(n),by(n); @@ -66,4 +95,10 @@ void export_geometry(py::module& m, py::class_& ctc, py::class_(m, "Polygon") + .def(py::init(&create_polygon_from_pylist), "list"_a) + .def(py::init>()) + ; + } diff --git a/python/src/core/graphics/codac_py_VIBesFig.cpp b/python/src/core/graphics/codac_py_VIBesFig.cpp index eb895a904..4ff9ebe4a 100644 --- a/python/src/core/graphics/codac_py_VIBesFig.cpp +++ b/python/src/core/graphics/codac_py_VIBesFig.cpp @@ -96,5 +96,9 @@ void export_VIBesFig(py::module& m) .def("draw_line", (void (VIBesFig::*)(const std::vector&,const std::vector&,const string&,const vibes::Params &))&VIBesFig::draw_line, "todo", "v_x"_a, "v_y"_a, "color"_a="", "params"_a=vibes::Params()) + + .def("draw_polygon", (void (VIBesFig::*)(const Polygon&,const string&,const vibes::Params &))&VIBesFig::draw_polygon, + VIBESFIG_VOID_DRAW_POLYGON_POLYGON_STRING_VIBESPARAMS, + "p"_a, "color"_a="", "params"_a=vibes::Params()) ; } \ No newline at end of file