Skip to content
Snippets Groups Projects
Commit 2b4077c3 authored by David Bergström's avatar David Bergström
Browse files

Add 2 classes for points

parent e9d51100
No related branches found
No related tags found
No related merge requests found
#include "library.h"
namespace py = pybind11;
void define_point(py::module & m)
{
// Note that Point2D has dynamic attributes, allowing students to add additional methods to it
py::class_<sc2::Point2D>(m, "Point2D", py::dynamic_attr())
.def(py::init<float, float>())
.def(py::init())
.def_readwrite("x", &sc2::Point2D::x)
.def_readwrite("y", &sc2::Point2D::y)
.def(py::self += py::self)
.def(py::self -= py::self)
.def(py::self *= float())
.def(py::self /= float())
// TODO: These does not compile
//.def(py::self == py::self)
//.def(py::self != py::self)
.def(py::self + py::self)
.def(py::self - py::self)
.def(py::self * float())
.def(float() * py::self)
.def(py::self / float())
.def(float() / py::self)
.def("__repr__",
[](const sc2::Point2D & p) {
return "<Point2D: (" + std::to_string(p.x) + ", " + std::to_string(p.y) + ")>";
})
.def("__str__",
[](const sc2::Point2D & p) {
return "(" + std::to_string(p.x) + ", " + std::to_string(p.y) + ")";
});
py::class_<sc2::Point2DI>(m, "Point2DI")
.def(py::init<int, int>())
.def_readwrite("x", &sc2::Point2DI::x)
.def_readwrite("y", &sc2::Point2DI::y)
.def(py::self == py::self)
.def(py::self != py::self);
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ PYBIND11_MODULE(library, m)
define_unit(m);
define_unittype(m);
define_util(m);
define_point(m);
py::class_<Coordinator>(m, "Coordinator")
.def(py::init())
......
......@@ -53,4 +53,5 @@ public:
void define_typeenums(pybind11::module & m);
void define_unit(pybind11::module & m);
void define_unittype(pybind11::module &m);
void define_util(pybind11::module &m);
\ No newline at end of file
void define_util(pybind11::module &m);
void define_point(pybind11::module &m);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment