Allow passing in the matrix map directly to a Geometry object

This commit is contained in:
Jeff Epler 2025-02-18 12:08:32 -06:00
parent cab2d4293d
commit 97d5a4454d
2 changed files with 22 additions and 3 deletions

View file

@ -84,16 +84,21 @@ struct matrix_geometry {
template <typename Cb>
matrix_geometry(size_t pixels_across, size_t n_addr_lines, int n_planes,
size_t width, size_t height, bool serpentine, const Cb &cb)
: matrix_geometry(
pixels_across, n_addr_lines, n_planes, width, height,
make_matrixmap(width, height, n_addr_lines, serpentine, cb)) {}
matrix_geometry(size_t pixels_across, size_t n_addr_lines, int n_planes,
size_t width, size_t height, matrix_map map)
: pixels_across(pixels_across), n_addr_lines(n_addr_lines),
n_planes(n_planes), width(width),
height(height), map{make_matrixmap(width, height, n_addr_lines,
serpentine, cb)} {
n_planes(n_planes), width(width), height(height), map(map) {
size_t pixels_down = 2u << n_addr_lines;
if (map.size() != pixels_down * pixels_across) {
throw std::range_error(
"map size does not match calculated pixel count");
}
}
size_t pixels_across, n_addr_lines;
int n_planes;
size_t width, height;

View file

@ -209,6 +209,20 @@ The default, 10, is the maximum value.
py::arg("serpentine") = true,
py::arg("rotation") = piomatter::orientation::normal,
py::arg("n_planes") = 10u)
.def(py::init([](size_t width, size_t height, size_t n_addr_lines,
piomatter::matrix_map map, size_t n_planes) {
size_t n_lines = 2 << n_addr_lines;
size_t pixels_across = width * height / n_lines;
for (auto el : map) {
if ((size_t)el >= width * height) {
throw std::out_of_range("Map element out of range");
}
}
return piomatter::matrix_geometry(
pixels_across, n_addr_lines, n_planes, width, height, map);
}),
py::arg("width"), py::arg("height"), py::arg("n_addr_lines"),
py::arg("map"), py::arg("n_planes") = 10u)
.def_readonly("width", &piomatter::matrix_geometry::width)
.def_readonly("height", &piomatter::matrix_geometry::height);