| 119 | |
| 120 | // Generate YAML content |
| 121 | export function generateYAML(metadata: MapMetadata): string { |
| 122 | const lines: string[] = []; |
| 123 | |
| 124 | // Required fields first |
| 125 | lines.push(`image: ${metadata.image}`); |
| 126 | lines.push(`resolution: ${metadata.resolution}`); |
| 127 | lines.push(`origin: [${metadata.origin.join(', ')}]`); |
| 128 | lines.push(`negate: ${metadata.negate}`); |
| 129 | lines.push(`occupied_thresh: ${metadata.occupied_thresh}`); |
| 130 | lines.push(`free_thresh: ${metadata.free_thresh}`); |
| 131 | |
| 132 | // Add any additional fields |
| 133 | for (const [key, value] of Object.entries(metadata)) { |
| 134 | if (!['image', 'resolution', 'origin', 'negate', 'occupied_thresh', 'free_thresh'].includes(key)) { |
| 135 | lines.push(`${key}: ${value}`); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return lines.join('\n'); |
| 140 | } |
| 141 | |
| 142 | // Convert canvas to PGM format |
| 143 | export function canvasToPGM(canvas: HTMLCanvasElement): ArrayBuffer { |