brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
add-puzzle-typeScaffold a new puzzle type across all 10+ pipeline integration points in jigsawR. Creates the core puzzle module, wires it into the unified pipeline (generation, positioning, rendering, adjacency), adds ggpuzzle geom/stat layers, updates DESCRIPTION and config.yml, extends the Shiny app, and creates a comprehensive test suite. Use when adding a completely n…
Independent GitHub snapshot · Automated classification · Original documentation governs
Scaffold new puzzle type across all pipeline integration points in jigsawR.
"triangular")Create R/<type>_puzzle.R with internal generation function:
#' Generate <type> puzzle pieces (internal)
#' @noRd
generate_<type>_pieces_internal <- function(params, seed) {
# 1. Initialize RNG state
# 2. Generate piece geometries
# 3. Build edge paths (SVG path data)
# 4. Compute adjacency
# 5. Return list: pieces, edges, adjacency, metadata
}
Follow pattern in R/voronoi_puzzle.R or R/snic_puzzle.R for structure.
Got: Function returns list with $pieces, $edges, $adjacency, $metadata.
If fail: Compare return structure against generate_voronoi_pieces_internal() to identify missing list elements or incorrect types.
Edit R/jigsawR_clean.R:
"<type>" to valid_types vector"<type>" -> "<type>_")# In valid_types
valid_types <- c("rectangular", "hexagonal", "concentric", "voronoi", "snic", "<type>")
Got: generate_puzzle(type = "<type>") accepted without "unknown type" error.
If fail: Verify type string added to valid_types exactly as spelled, parameter extraction covers all required type-specific arguments.
Edit R/unified_piece_generation.R:
generate_pieces_internal()# In the switch/dispatch
"<type>" = generate_<type>_pieces_internal(params, seed)
Got: Pieces generated when type dispatched.
If fail: Confirm dispatch case string matches type name exactly. generate_<type>_pieces_internal defined and exported from puzzle module.
Edit R/piece_positioning.R:
Add positioning dispatch for new type. Most types use shared positioning logic. Some need custom handling.
Got: apply_piece_positioning() handles new type without errors. Pieces placed at correct coordinates.
If fail: Check whether new type needs custom positioning logic or can reuse shared positioning path. Add dispatch case if default path does not apply.
Edit R/unified_renderer.R:
render_puzzle_svg()get_<type>_edge_paths()get_<type>_piece_name()Got: SVG output generated for new type with correct piece outlines and edge paths.
If fail: Verify get_<type>_edge_paths() returns valid SVG path data. get_<type>_piece_name() produces unique identifiers for each piece.
Edit R/adjacency_api.R:
Add neighbor dispatch so get_neighbors() and get_adjacency() work for new type.
Got: get_neighbors(result, piece_id) returns correct neighbors for any piece in puzzle.
If fail: Check adjacency dispatch returns correct data structure. Test with small grid and manually verify neighbor relationships against geometry.
Edit R/geom_puzzle.R:
Create geom_puzzle_<type>() using make_puzzle_layer() factory:
#' @export
geom_puzzle_<type> <- function(mapping = NULL, data = NULL, ...) {
make_puzzle_layer(type = "<type>", mapping = mapping, data = data, ...)
}
Got: ggplot() + geom_puzzle_<type>(aes(...)) renders without error.
If fail: Verify make_puzzle_layer() receives correct type string. Geom function exported in NAMESPACE via @export.
Edit R/stat_puzzle.R:
compute_panel()Got: Stat layer computes puzzle geometry correctly. Produces expected number of polygons.
If fail: Check compute_panel() dispatch case returns data frame with required columns (x, y, group, piece_id). Default parameters sensible for new type.
Edit DESCRIPTION:
Suggests: (if external dependency)Collate: to include new R file (alphabetical order)Got: devtools::document() succeeds. No NOTE about unlisted files.
If fail: Check new R file listed in Collate: field in alphabetical order. Any new Suggests packages spelled correctly with version constraints.
Edit inst/config.yml:
Add defaults and constraints for new type:
<type>:
grid:
default: [3, 3]
min: [2, 2]
max: [20, 20]
size:
default: [300, 300]
min: [100, 100]
max: [2000, 2000]
tabsize:
default: 20
min: 5
max: 50
# Add type-specific params here
Got: Config valid YAML. Defaults produce working puzzle when used by generate_puzzle().
If fail: Validate YAML with yaml::yaml.load_file("inst/config.yml"). Ensure default grid and size values produce sensible puzzle (not too small or too large).
Edit inst/shiny-app/app.R:
Got: Shiny app shows new type in dropdown. Generates puzzles when selected.
If fail: Check type added to choices argument of UI selector. Conditional panel for type-specific parameters uses conditionalPanel(condition = "input.type == '<type>'"). Server-side handler passes correct parameters.
Create tests/testthat/test-<type>-puzzles.R:
test_that("<type> puzzle generates correct piece count", { ... })
test_that("<type> puzzle respects seed reproducibility", { ... })
test_that("<type> adjacency returns valid neighbors", { ... })
test_that("<type> fusion merges pieces correctly", { ... })
test_that("<type> geom layer renders without error", { ... })
test_that("<type> SVG output is well-formed", { ... })
test_that("<type> config constraints are enforced", { ... })
Type requires external package? Wrap tests with skip_if_not_installed().
Got: All tests pass. No skips unless external dependency missing.
If fail: Check each integration point individually. Most common issue: missing dispatch cases — run grep -rn "switch\|valid_types" R/ to find all dispatch locations.
generate_puzzle(type = "<type>") produces valid outputdevtools::test() passes with new testsdevtools::check() returns 0 errors, 0 warningsdevtools::document() succeeds (NAMESPACE updated)paste(a, b, sep = "-")? Negative piece labels produce keys like "1--1". Use "|" separator instead. Split with "\\|".cat() for output: Always use cli package logging wrappers (log_info, log_warn, etc.)yaml::yaml.load_file("inst/config.yml")generate-puzzle — test new type after scaffoldingrun-puzzle-tests — run full test suite to verify integrationvalidate-piles-notation — test fusion with new typewrite-testthat-tests — general test-writing patternswrite-roxygen-docs — document new geom function