* Parse multiple trajectories from input (separated by blank lines) * Supports optional trajectory names via # comment lines before each block. * Example: * # My Trajectory * [[[1,0,0,0], ...], ...] * * @param {string} input - The input string potentially containin
(input, format = 'matrix')
| 16 | * @returns {Object} - { success: boolean, trajectories: array, errors: array, totalCount: number } |
| 17 | */ |
| 18 | static parseMultiple(input, format = 'matrix') { |
| 19 | const trajectories = []; |
| 20 | const errors = []; |
| 21 | let totalCount = 0; |
| 22 | |
| 23 | // Split by double newlines or lines that only contain whitespace between arrays |
| 24 | const blocks = this.splitIntoBlocks(input); |
| 25 | |
| 26 | if (blocks.length === 0) { |
| 27 | return { |
| 28 | success: false, |
| 29 | trajectories: [], |
| 30 | errors: ['No valid input found'], |
| 31 | totalCount: 0 |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | blocks.forEach((block, index) => { |
| 36 | // Extract name from # comment if present |
| 37 | const { name, content } = this.extractNameFromBlock(block, index); |
| 38 | |
| 39 | const result = this.parse(content, format); |
| 40 | if (result.success) { |
| 41 | trajectories.push({ |
| 42 | id: index, |
| 43 | name: name, |
| 44 | poses: result.data, |
| 45 | count: result.count, |
| 46 | visible: true |
| 47 | }); |
| 48 | totalCount += result.count; |
| 49 | } else { |
| 50 | errors.push(`${name}: ${result.error}`); |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | return { |
| 55 | success: trajectories.length > 0, |
| 56 | trajectories: trajectories, |
| 57 | errors: errors, |
| 58 | totalCount: totalCount |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Extract trajectory name from a # comment line at the start of a block |
no test coverage detected