Commit c0097a78 authored by Davis King's avatar Davis King

Added dpoint to the python API.

parent da943c69
......@@ -50,6 +50,7 @@ PYBIND11_MAKE_OPAQUE(sparse_ranking_pairs);
PYBIND11_MAKE_OPAQUE(std::vector<dlib::point>);
PYBIND11_MAKE_OPAQUE(std::vector<dlib::dpoint>);
#endif // DLIB_PyTHON_OPAQUE_TYPES_H_
......@@ -138,8 +138,24 @@ string point__str__(const point& p)
return sout.str();
}
string dpoint__repr__ (const dpoint& p)
{
std::ostringstream sout;
sout << "dpoint(" << p.x() << ", " << p.y() << ")";
return sout.str();
}
string dpoint__str__(const dpoint& p)
{
std::ostringstream sout;
sout << "(" << p.x() << ", " << p.y() << ")";
return sout.str();
}
long point_x(const point& p) { return p.x(); }
long point_y(const point& p) { return p.y(); }
double dpoint_x(const dpoint& p) { return p.x(); }
double dpoint_y(const dpoint& p) { return p.y(); }
// ----------------------------------------------------------------------------------------
void bind_vector(py::module& m)
......@@ -179,4 +195,23 @@ void bind_vector(py::module& m)
.def("extend", extend_vector_with_python_list<point>)
.def(py::pickle(&getstate<type>, &setstate<type>));
}
{
typedef dpoint type;
py::class_<type>(m, "dpoint", "This object represents a single point of floating point coordinates that maps directly to a dlib::dpoint.")
.def(py::init<double,double>(), py::arg("x"), py::arg("y"))
.def("__repr__", &dpoint__repr__)
.def("__str__", &dpoint__str__)
.def_property("x", &dpoint_x, [](dpoint& p, double x){p.x()=x;}, "The x-coordinate of the dpoint.")
.def_property("y", &dpoint_y, [](dpoint& p, double y){p.x()=y;}, "The y-coordinate of the dpoint.")
.def(py::pickle(&getstate<type>, &setstate<type>));
}
{
typedef std::vector<dpoint> type;
py::bind_vector<type>(m, "dpoints", "An array of dpoint objects.")
.def("clear", &type::clear)
.def("resize", resize<type>)
.def("extend", extend_vector_with_python_list<dpoint>)
.def(py::pickle(&getstate<type>, &setstate<type>));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment