"git@gitlab.liu.se:starcraft-ai-course/pycommandcenter.git" did not exist on "05c2d7f9699039a4aed8f47d060df53d6f939e31"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#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);
}