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
於 jigsawR 跨所有管線整合點為新拼圖類型搭建鷹架。
"triangular")建立 R/<type>_puzzle.R,含內部生成函式:
#' 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
}
依 R/voronoi_puzzle.R 或 R/snic_puzzle.R 之結構為範。
預期: 函式回傳含 $pieces、$edges、$adjacency、$metadata 之 list。
失敗時: 與 generate_voronoi_pieces_internal() 比對回傳結構,以辨缺失之 list 元素或型別錯誤。
編輯 R/jigsawR_clean.R:
"<type>" 加入 valid_types 向量"<type>" -> "<type>_")# In valid_types
valid_types <- c("rectangular", "hexagonal", "concentric", "voronoi", "snic", "<type>")
預期: generate_puzzle(type = "<type>") 受納而無 "unknown type" 之誤。
失敗時: 驗證類型字串拼寫無誤地加入 valid_types,且參數提取涵蓋一切類型特有之必要引數。
編輯 R/unified_piece_generation.R:
generate_pieces_internal() 加入分派 case# In the switch/dispatch
"<type>" = generate_<type>_pieces_internal(params, seed)
預期: 分派類型時,拼塊得以生成。
失敗時: 確認分派 case 字串與類型名完全相符,且 generate_<type>_pieces_internal 已於拼圖模組定義並輸出。
編輯 R/piece_positioning.R:
為新類型加入定位分派。多數類型用共用之定位邏輯,然有些須自訂。
預期: apply_piece_positioning() 處理新類型而無誤,且拼塊置於正確座標。
失敗時: 查新類型是否需自訂定位邏輯或可重用共用定位路徑。預設路徑不適用時加分派 case。
編輯 R/unified_renderer.R:
render_puzzle_svg() 加入渲染 caseget_<type>_edge_paths()get_<type>_piece_name()預期: 為新類型生成 SVG 輸出,附正確之拼塊輪廓與邊路徑。
失敗時: 驗證 get_<type>_edge_paths() 回傳有效之 SVG 路徑資料,且 get_<type>_piece_name() 為各拼塊產唯一識別。
編輯 R/adjacency_api.R:
加入鄰接分派,使 get_neighbors() 與 get_adjacency() 對新類型有效。
預期: get_neighbors(result, piece_id) 為拼圖中任一塊回傳正確鄰居。
失敗時: 查鄰接分派是否回傳正確資料結構。以小格網測試並依幾何手動驗證鄰接關係。
編輯 R/geom_puzzle.R:
以 make_puzzle_layer() 工廠建立 geom_puzzle_<type>():
#' @export
geom_puzzle_<type> <- function(mapping = NULL, data = NULL, ...) {
make_puzzle_layer(type = "<type>", mapping = mapping, data = data, ...)
}
預期: ggplot() + geom_puzzle_<type>(aes(...)) 渲染而無誤。
失敗時: 驗證 make_puzzle_layer() 收到正確之類型字串,且 geom 函式已透過 @export 於 NAMESPACE 輸出。
編輯 R/stat_puzzle.R:
compute_panel() 加入分派 case預期: stat 層正確計算拼圖幾何,並產出預期數量之多邊形。
失敗時: 查 compute_panel() 分派 case 是否回傳含必要欄(x、y、group、piece_id)之 data frame,且預設參數對新類型合宜。
編輯 DESCRIPTION:
Suggests:(若為外部依賴)Collate: 以納入新 R 檔(按字母順序)預期: devtools::document() 成功。無關於未列檔案之 NOTE。
失敗時: 查新 R 檔是否按字母順序列於 Collate: 欄,且任何新 Suggests 套件之拼寫與版本約束皆正確。
編輯 inst/config.yml:
為新類型加入預設與約束:
<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
預期: 配置為有效之 YAML。預設於 generate_puzzle() 用之時產出可用拼圖。
失敗時: 以 yaml::yaml.load_file("inst/config.yml") 驗證 YAML。確保預設之 grid 與 size 值產合宜拼圖(不過小亦不過大)。
編輯 inst/shiny-app/app.R:
預期: Shiny app 於下拉選單中顯示新類型,並於選定時生成拼圖。
失敗時: 查類型是否加入 UI 選擇器之 choices 引數,類型特有參數之條件式面板是否用 conditionalPanel(condition = "input.type == '<type>'"),且伺服端處理器是否傳遞正確參數。
建立 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", { ... })
若類型需外部套件,以 skip_if_not_installed() 包裝測試。
預期: 一切測試通過。除非外部依賴缺失,否則無 skip。
失敗時: 個別檢查各整合點。最常見之問題乃缺失之分派 case——行 grep -rn "switch\|valid_types" R/ 以尋一切分派位置。
generate_puzzle(type = "<type>") 產有效輸出devtools::test() 連同新測試通過devtools::check() 回傳 0 errors、0 warningsdevtools::document() 成功(NAMESPACE 已更新)paste(a, b, sep = "-") 建鄰接鍵時,負拼塊標籤產如 "1--1" 之鍵。改用 "|" 分隔符並以 "\\|" 切分cat() 輸出:務用 cli 套件之記錄包裝(log_info、log_warn 等)yaml::yaml.load_file("inst/config.yml") 測試generate-puzzle — 鷹架後測試新類型run-puzzle-tests — 執行完整測試套件以驗證整合validate-piles-notation — 以新類型測試融合write-testthat-tests — 通用測試撰寫模式write-roxygen-docs — 為新 geom 函式撰寫文件