mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-04 13:34:24 +08:00
Add docs and tests for unary op on class (#1814)
This commit is contained in:
@@ -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))
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user