summaryrefslogtreecommitdiff
path: root/morphology-img/src/file_gen.rs
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-17 08:49:07 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-17 08:49:07 +0100
commite37f7ba671f3e80396e7a4ac3a461365bd0ca78a (patch)
tree372bcc9bac7295fab920447fd1c8b84b257af337 /morphology-img/src/file_gen.rs
parentfc43589d3a5206a9b555dc868a1db0c92af53802 (diff)
feature: ly processing batch chunking
Diffstat (limited to 'morphology-img/src/file_gen.rs')
-rw-r--r--morphology-img/src/file_gen.rs46
1 files changed, 43 insertions, 3 deletions
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<Vec<PathBuf>, 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<Vec<PathBuf>, 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)?;