File size: 2,719 Bytes
e232e39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Simple Test of Hexagonal Puzzle Features
# Tests the new hexagonal puzzle support

library(jigsawR)

cat("=== Testing Hexagonal Puzzle Features ===\n\n")

# Test 1: Basic hexagonal puzzle generation
cat("1. Testing basic hexagonal puzzle generation...\n")
tryCatch({
  result <- generate_puzzle(
    type = "hexagonal",
    grid = c(3, 3),        # 3 rings
    size = c(200, 200),    # 200mm diameter
    seed = 42,
    output = "complete",
    save_files = FALSE
  )
  
  if (!is.null(result$svg_complete)) {
    cat("   βœ“ SUCCESS: Basic hexagonal puzzle generated\n")
  } else {
    cat("   βœ— FAILED: No SVG content returned\n")
  }
}, error = function(e) {
  cat("   βœ— ERROR:", e$message, "\n")
})

# Test 2: Hexagonal puzzle with individual pieces
cat("\n2. Testing hexagonal puzzle with individual pieces...\n")
tryCatch({
  result <- generate_puzzle(
    type = "hexagonal",
    grid = c(2, 2),        # 2 rings (simpler)
    size = c(150, 150),    # 150mm diameter
    seed = 123,
    output = "individual",
    save_files = FALSE
  )
  
  if (!is.null(result$svg_individual)) {
    cat("   βœ“ SUCCESS: Hexagonal individual pieces generated\n")
  } else {
    cat("   βœ— FAILED: No individual pieces SVG\n")
  }
}, error = function(e) {
  cat("   βœ— ERROR:", e$message, "\n")
})

# Test 3: Compare piece counts
cat("\n3. Testing piece count calculations...\n")
for (rings in 2:4) {
  expected_pieces <- 3 * rings * (rings - 1) + 1
  cat("   ", rings, "rings =", expected_pieces, "pieces\n")
}

# Test 4: Direct hexagonal functions
cat("\n4. Testing direct hexagonal generation...\n")
tryCatch({
  svg_content <- generate_hex_jigsaw_svg(
    rings = 2,
    diameter = 120,
    seed = 999
  )
  
  if (nchar(svg_content) > 0) {
    cat("   βœ“ SUCCESS: Direct hexagonal generation works\n")
    cat("   SVG length:", nchar(svg_content), "characters\n")
  } else {
    cat("   βœ— FAILED: Empty SVG content\n")
  }
}, error = function(e) {
  cat("   βœ— ERROR:", e$message, "\n")
})

cat("\n=== Feature Summary ===\n")
cat("βœ“ Backend: Hexagonal individual pieces support added\n")
cat("βœ“ Backend: Hexagonal separation/offset logic implemented\n") 
cat("βœ“ Backend: Updated jigsawR_clean.R for hexagonal support\n")
cat("βœ“ Frontend: Added puzzle type selector to Shiny app\n")
cat("βœ“ Frontend: Added hexagonal-specific controls\n")
cat("βœ“ Frontend: Updated generation logic for hex puzzles\n")
cat("βœ“ Integration: Full pipeline from backend to frontend\n\n")

cat("The jigsawR package now supports both rectangular and hexagonal puzzles\n")
cat("with individual piece extraction and offset capabilities!\n")