Skip to content

Commit

Permalink
Allow passing in the matrix map directly to a Geometry object
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Feb 18, 2025
1 parent 86cef28 commit d120eca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/include/piomatter/matrixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/pymain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d120eca

Please sign in to comment.