From e37f7ba671f3e80396e7a4ac3a461365bd0ca78a Mon Sep 17 00:00:00 2001 From: jacksonfu14 Date: Mon, 17 Nov 2025 08:49:07 +0100 Subject: feature: ly processing batch chunking --- morphology-img/src/file_gen.rs | 46 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'morphology-img/src/file_gen.rs') diff --git a/morphology-img/src/file_gen.rs b/morphology-img/src/file_gen.rs index edeeeeb..dffb7bb 100644 --- a/morphology-img/src/file_gen.rs +++ b/morphology-img/src/file_gen.rs @@ -164,11 +164,51 @@ pub fn generate_ly_files( sequences: &[Sequence], temp_dir: &Path, ) -> Result, RenderError> { - let total_count = sequences.len(); - let mut paths = Vec::with_capacity(total_count); + generate_ly_files_with_offset(sequences, temp_dir, 0, sequences.len()) +} + +/// Generates .ly files for multiple sequences with custom offset and total count. +/// +/// This function is used internally for batch processing to maintain proper +/// global indexing across batches. The offset parameter allows each batch to +/// start numbering from its global position, while total_count ensures +/// consistent padding width across all batches. +/// +/// # Arguments +/// - `sequences`: The sequences to generate files for (batch) +/// - `temp_dir`: The directory to write files to +/// - `offset`: Starting index in the global sequence list +/// - `total_count`: Total number of sequences across all batches +/// +/// # Returns +/// A vector of paths to the generated .ly files +/// +/// # Examples +/// ```no_run +/// use morphology::{Sequence, Value}; +/// use morphology_img::file_gen::{generate_ly_files_with_offset, create_temp_dir}; +/// +/// // Second batch of a 12-sequence job +/// let sequences = vec![ +/// Sequence::new(vec![Value::new(5, 0)]), +/// Sequence::new(vec![Value::new(6, 0)]), +/// ]; +/// +/// let temp_dir = create_temp_dir().unwrap(); +/// // offset=5, total_count=12 ensures filenames are sequence-05.ly, sequence-06.ly +/// let paths = generate_ly_files_with_offset(&sequences, temp_dir.path(), 5, 12).unwrap(); +/// ``` +pub fn generate_ly_files_with_offset( + sequences: &[Sequence], + temp_dir: &Path, + offset: usize, + total_count: usize, +) -> Result, RenderError> { + let mut paths = Vec::with_capacity(sequences.len()); for (index, sequence) in sequences.iter().enumerate() { - let filename = generate_filename(index, total_count); + let global_index = offset + index; + let filename = generate_filename(global_index, total_count); let output_path = temp_dir.join(&filename); generate_ly_file(sequence, &output_path)?; -- cgit v1.2.3