From 4c033fadab859a7cb445e0f6033f0fea74933567 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 22 Dec 2024 15:08:27 +0800 Subject: [PATCH] feat: mirror interfaces of Layout --- src/core_ffi/python_ffi/binder/klsk_code.cc | 7 ++++++- src/core_ffi/python_ffi/include/py_ffi/layout.h | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/core_ffi/python_ffi/binder/klsk_code.cc b/src/core_ffi/python_ffi/binder/klsk_code.cc index a278c63..f8599bc 100644 --- a/src/core_ffi/python_ffi/binder/klsk_code.cc +++ b/src/core_ffi/python_ffi/binder/klsk_code.cc @@ -65,7 +65,7 @@ static void bind_layout(const py::module_ &mod) { .def_property_readonly("n_1x1", &PyLayout::n_1x1) .def_property_readonly("n_1x2", &PyLayout::n_1x2) .def_property_readonly("n_2x1", &PyLayout::n_2x1) - .def_property_readonly("n_2x2", &PyLayout::n_2x2) // TODO: return `1` directly + .def_property_readonly("n_2x2", [](const PyLayout&) { return 1; }) .def_property_readonly("type_id", &PyLayout::type_id) .def_property_readonly("pattern_id", &PyLayout::pattern_id) @@ -74,6 +74,11 @@ static void bind_layout(const py::module_ &mod) { .def_property_readonly("group", &PyLayout::group_info) .def_property_readonly("case_info", &PyLayout::case_info) + .def("to_vertical_mirror", &PyLayout::to_vertical_mirror) + .def("to_horizontal_mirror", &PyLayout::to_horizontal_mirror) + .def_property_readonly("is_vertical_mirror", &PyLayout::is_vertical_mirror) + .def_property_readonly("is_horizontal_mirror", &PyLayout::is_horizontal_mirror) + .def_static("check", py::overload_cast(&PyLayout::check)) .def_static("check", py::overload_cast(&PyLayout::check)); } diff --git a/src/core_ffi/python_ffi/include/py_ffi/layout.h b/src/core_ffi/python_ffi/include/py_ffi/layout.h index 98b808a..91c34e4 100644 --- a/src/core_ffi/python_ffi/include/py_ffi/layout.h +++ b/src/core_ffi/python_ffi/include/py_ffi/layout.h @@ -119,8 +119,20 @@ public: return std::get<1>(group::BLOCK_NUM[type_id()]); } - [[nodiscard]] uint8_t n_2x2() const noexcept { - return 1; + [[nodiscard]] bool is_vertical_mirror() const noexcept { + return code_.is_vertical_mirror(); + } + + [[nodiscard]] bool is_horizontal_mirror() const noexcept { + return code_.is_horizontal_mirror(); + } + + [[nodiscard]] PyLayout to_vertical_mirror() const noexcept { + return std::bit_cast(code_.to_vertical_mirror()); + } + + [[nodiscard]] PyLayout to_horizontal_mirror() const noexcept { + return std::bit_cast(code_.to_horizontal_mirror()); } // ------------------------------------------------------------------------------------- //