matt-dray / pixeltrix

:space_invader::computer_mouse: R package: make pixel art interactively in a plot window, get a matrix, make a gif
Other
21 stars 0 forks source link

User should be able to provide a matrix of their own for editing #6

Closed matt-dray closed 1 year ago

matt-dray commented 1 year ago

Maybe a m(atrix) argument overrides supply of n_row and n_col?

But additional logic is required when editing a provided matrix. Need to assess things like its dimensions and how many values it takes (could just start by insisting 0,1 only, but ideally will allow for more in future as per #4).

So maybe it's a separate 'edit' function, like edit_pixels() rather than click_pixels()?

matt-dray commented 1 year ago

Unique values in the user-supplied matrix should be sorted and zero-indexed, where NA will always default to 0. This works fine for matrices like m <- matrix(sample(c(LETTERS[1:2], NA), 9, replace = TRUE), 3). In this case, the values will be sorted to NA, "a", "b" and then reassigned integer values of 0L:2L.

But what if the users provides a matrix like m <- matrix(sample(c(2, 4), 9, replace = TRUE), 3) (e.g. an output from click_pixels())? This should probably be interpreted to mean that the max pixel-state value is 4, even though not all the states from 0 to 4 are represented in the matrix. In other words, don't convert 2L, 4L to 0L:1L; instead, assume 0L:4L.

matt-dray commented 1 year ago

edit_pixels() is now in the package, as of https://github.com/matt-dray/pixeltrix/commit/d6f0987fab76ea3e828be28ff645c7c000379ebe. For now, for simplicity, it only takes matrices composed of integers, i.e. like the ones that come out of click_pixels(). Still might be nice for people to provide a generic matrix, so leaving open for now.

matt-dray commented 1 year ago

Nah, out of scope, I reckon.