From 7f437810fded411910eb8b3586441fe3f7f4b9e5 Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Thu, 12 Mar 2026 09:00:06 -0700 Subject: [PATCH] Move MjrRect pybind11 definition to structs.cc. mjrRect is a common type that will be re-used across different rendering APIs, not just mjr_ APIs. PiperOrigin-RevId: 882620060 Change-Id: I7f77ac9298c52c454d94c46379ff5270fd833f26 --- python/mujoco/render.cc | 19 ------------------- python/mujoco/structs.cc | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/python/mujoco/render.cc b/python/mujoco/render.cc index c621cd0e..d16af680 100644 --- a/python/mujoco/render.cc +++ b/python/mujoco/render.cc @@ -158,25 +158,6 @@ PYBIND11_MODULE(_render, pymodule) { // for MjWrapper types and therefore generates prettier docstrings. py::module::import("mujoco._structs"); - py::class_ mjrRect(pymodule, "MjrRect"); - mjrRect.def(py::init([](int left, int bottom, int width, int height) { - return raw::MjrRect{left, bottom, width, height}; - }), - py::arg("left"), py::arg("bottom"), py::arg("width"), - py::arg("height")); - mjrRect.def("__copy__", - [](const raw::MjrRect& other) { return raw::MjrRect(other); }); - mjrRect.def("__deepcopy__", [](const raw::MjrRect& other, py::dict) { - return raw::MjrRect(other); - }); - DefineStructFunctions(mjrRect); -#define X(var) mjrRect.def_readwrite(#var, &raw::MjrRect::var) - X(left); - X(bottom); - X(width); - X(height); -#undef X - py::class_ mjrContext(pymodule, "MjrContext"); mjrContext.def(py::init<>()); mjrContext.def(py::init()); diff --git a/python/mujoco/structs.cc b/python/mujoco/structs.cc index d8a88f0b..9f616650 100644 --- a/python/mujoco/structs.cc +++ b/python/mujoco/structs.cc @@ -898,6 +898,27 @@ This is useful for example when the MJB is not available as a file on disk.)")); X(tolrange); #undef X + + // ==================== MJRRECT ============================================== + py::class_ mjrRect(m, "MjrRect"); + mjrRect.def(py::init([](int left, int bottom, int width, int height) { + return raw::MjrRect{left, bottom, width, height}; + }), + py::arg("left"), py::arg("bottom"), py::arg("width"), + py::arg("height")); + mjrRect.def("__copy__", + [](const raw::MjrRect& other) { return raw::MjrRect(other); }); + mjrRect.def("__deepcopy__", [](const raw::MjrRect& other, py::dict) { + return raw::MjrRect(other); + }); + DefineStructFunctions(mjrRect); +#define X(var) mjrRect.def_readwrite(#var, &raw::MjrRect::var) + X(left); + X(bottom); + X(width); + X(height); +#undef X + // ==================== MJVPERTURB =========================================== py::class_ mjvPerturb(m, "MjvPerturb"); mjvPerturb.def(py::init<>());