Add docs and tests for unary op on class (#1814)

This commit is contained in:
Ian Bell
2019-06-22 04:07:41 -06:00
committed by Wenzel Jakob
parent a1b71df137
commit 502ffe50a9
3 changed files with 12 additions and 7 deletions

View File

@@ -23,6 +23,7 @@ public:
std::string toString() const { return "[" + std::to_string(x) + ", " + std::to_string(y) + "]"; }
Vector2 operator-() const { return Vector2(-x, -y); }
Vector2 operator+(const Vector2 &v) const { return Vector2(x + v.x, y + v.y); }
Vector2 operator-(const Vector2 &v) const { return Vector2(x - v.x, y - v.y); }
Vector2 operator-(float value) const { return Vector2(x - value, y - value); }
@@ -104,6 +105,7 @@ TEST_SUBMODULE(operators, m) {
.def(float() - py::self)
.def(float() * py::self)
.def(float() / py::self)
.def(-py::self)
.def("__str__", &Vector2::toString)
.def(hash(py::self))
;