runarium 0.1.0

Generate animated videos from GPS running/cycling data with real-time statistics
Documentation
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
// Re-export all config types for public API
pub use super::config::{Color, FileConfig, Font, RouteColor, RouteScale};

/// Configuration for pace and distance display
#[derive(Debug, Clone)]
pub struct PaceDistConfig {
  /// Font scale for pace/distance text
  pub font_scale: f64,
  /// Thickness of the text
  pub thickness: i32,
  /// Font family for text
  pub font: Font,
  /// Position for the pace/distance bar (None = auto)
  pub position: Option<(i32, i32)>,
  /// Whether to show pace
  pub show_pace: bool,
  /// Whether to show distance
  pub show_distance: bool,
}

impl PaceDistConfig {
  /// Creates a new PaceDistConfig with custom settings
  pub fn new(
    font_scale: f64,
    thickness: i32,
    font: Font,
    position: Option<(i32, i32)>,
    show_pace: bool,
    show_distance: bool,
  ) -> Self {
    Self {
      font_scale,
      thickness,
      font,
      position,
      show_pace,
      show_distance,
    }
  }

  /// Creates configuration for large text
  pub fn large_text() -> Self {
    Self {
      font_scale: 0.8,
      thickness: 2,
      font: Font::Duplex,
      position: None,
      show_pace: true,
      show_distance: true,
    }
  }

  /// Creates configuration with only pace
  pub fn pace_only() -> Self {
    Self {
      font_scale: 0.5,
      thickness: 1,
      font: Font::Simplex,
      position: None,
      show_pace: true,
      show_distance: false,
    }
  }
}

impl Default for PaceDistConfig {
  /// Creates default configuration
  fn default() -> Self {
    Self {
      font_scale: 0.5,
      thickness: 1,
      font: Font::Simplex,
      position: None,
      show_pace: true,
      show_distance: true,
    }
  }
}

/// Complete configuration for route video generation
#[derive(Debug, Clone)]
pub struct LapDataConfig {
  /// Position of the lap panel as percentage (x_percent, y_percent) where 0.0-1.0
  pub position: (f64, f64),
  /// Font scale (fixed at 0.5)
  pub font_scale: f64,
  /// Text thickness (fixed at 1)
  pub thickness: i32,
  /// Font family for text
  pub font: Font,
  /// Text color for lap data
  pub text_color: Color,
  /// Whether to show heart rate
  pub show_heart_rate: bool,
  /// Whether to show stride length
  pub show_stride_length: bool,
  /// Whether to show pace bars
  pub show_pace_bars: bool,
}

impl LapDataConfig {
  /// Creates a new LapDataConfig with custom settings
  #[allow(clippy::too_many_arguments)]
  pub fn new(
    position: (f64, f64),
    font_scale: f64,
    thickness: i32,
    font: Font,
    text_color: Color,
    show_heart_rate: bool,
    show_stride_length: bool,
    show_pace_bars: bool,
  ) -> Self {
    Self {
      position,
      font_scale,
      thickness,
      font,
      text_color,
      show_heart_rate,
      show_stride_length,
      show_pace_bars,
    }
  }

  /// Creates minimal configuration (pace only, no extras)
  pub fn minimal() -> Self {
    Self {
      position: (0.5, 0.09), // 50% x, 9% y
      font_scale: 0.5,
      thickness: 1,
      font: Font::Simplex,
      text_color: Color::White,
      show_heart_rate: false,
      show_stride_length: false,
      show_pace_bars: true,
    }
  }

  /// Creates detailed configuration (all stats, larger bars)
  pub fn detailed() -> Self {
    Self {
      position: (0.5, 0.07), // 50% x, 7% y
      font_scale: 0.5,
      thickness: 1,
      font: Font::Simplex,
      text_color: Color::White,
      show_heart_rate: true,
      show_stride_length: true,
      show_pace_bars: true,
    }
  }
}

impl Default for LapDataConfig {
  /// Creates default configuration
  fn default() -> Self {
    Self {
      position: (0.5, 0.09), // 50% x, 9% y
      font_scale: 0.5,
      thickness: 1,
      font: Font::Simplex,
      text_color: Color::White,
      show_heart_rate: true,
      show_stride_length: true,
      show_pace_bars: true,
    }
  }
}

/// Complete configuration for route video generation
#[derive(Debug, Clone)]
pub struct RouteVideoConfig {
  /// Route scaling and positioning
  pub route_scale: RouteScale,
  /// Color scheme
  pub colors: RouteColor,
  /// Pace and distance display settings
  pub pace_dist: PaceDistConfig,
  /// Lap statistics settings
  pub lap_data: LapDataConfig,
  /// File paths configuration
  pub file_config: FileConfig,
  /// Whether to show the bottom pace/distance bar
  pub show_bottom_bar: bool,
  /// Whether to show the progressive route animation
  pub show_route: bool,
  /// Whether to show the lap data panel
  pub show_lap_data: bool,
}

impl RouteVideoConfig {
  /// Creates a new RouteVideoConfig with all custom settings
  #[allow(clippy::too_many_arguments)]
  pub fn new(
    route_scale: RouteScale,
    colors: RouteColor,
    pace_dist: PaceDistConfig,
    lap_data: LapDataConfig,
    file_config: FileConfig,
    show_bottom_bar: bool,
    show_route: bool,
    show_lap_data: bool,
  ) -> Self {
    Self {
      route_scale,
      colors,
      pace_dist,
      lap_data,
      file_config,
      show_bottom_bar,
      show_route,
      show_lap_data,
    }
  }

  /// Creates a minimalist configuration
  pub fn minimalist() -> Self {
    Self {
      route_scale: RouteScale::default(),
      colors: RouteColor::default(),
      pace_dist: PaceDistConfig::pace_only(),
      lap_data: LapDataConfig::minimal(),
      show_bottom_bar: true,
      show_route: true,
      show_lap_data: true,
      file_config: FileConfig::default(),
    }
  }

  /// Creates a detailed configuration with all features
  pub fn detailed() -> Self {
    Self {
      route_scale: RouteScale::large(),
      colors: RouteColor::default(),
      pace_dist: PaceDistConfig::large_text(),
      lap_data: LapDataConfig::detailed(),
      show_bottom_bar: true,
      show_route: true,
      show_lap_data: true,
      file_config: FileConfig::default(),
    }
  }

  /// Creates a vibrant neon-themed configuration
  pub fn neon() -> Self {
    Self {
      route_scale: RouteScale::centered(),
      colors: RouteColor::neon_scheme(),
      pace_dist: PaceDistConfig::default(),
      lap_data: LapDataConfig::default(),
      show_bottom_bar: true,
      show_route: true,
      show_lap_data: true,
      file_config: FileConfig::default(),
    }
  }
}

impl Default for RouteVideoConfig {
  /// Creates default configuration
  fn default() -> Self {
    Self {
      route_scale: RouteScale::default(),
      colors: RouteColor::default(),
      pace_dist: PaceDistConfig::default(),
      lap_data: LapDataConfig::default(),
      show_bottom_bar: true,
      show_route: true,
      show_lap_data: true,
      file_config: FileConfig::default(),
    }
  }
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn test_color_to_bgra() {
    assert_eq!(
      Color::Red.to_bgra(),
      [0.0, 0.0, 255.0, 0.0]
    );
    assert_eq!(
      Color::Green.to_bgra(),
      [0.0, 255.0, 0.0, 0.0]
    );
    assert_eq!(
      Color::Blue.to_bgra(),
      [255.0, 0.0, 0.0, 0.0]
    );
    assert_eq!(
      Color::White.to_bgra(),
      [255.0, 255.0, 255.0, 0.0]
    );
    assert_eq!(
      Color::Black.to_bgra(),
      [0.0, 0.0, 0.0, 0.0]
    );
  }

  #[test]
  fn test_route_scale_presets() {
    let default = RouteScale::default();
    assert_eq!(default.scale, 0.2);
    assert_eq!(default.offset_x_percent, 0.1);
    assert_eq!(default.offset_y_percent, 0.1);

    let centered = RouteScale::centered();
    assert_eq!(centered.scale, 0.4);
    assert_eq!(centered.offset_x_percent, 0.3);
    assert_eq!(centered.offset_y_percent, 0.3);

    let large = RouteScale::large();
    assert_eq!(large.scale, 0.7);
    assert_eq!(large.offset_x_percent, 0.15);
    assert_eq!(large.offset_y_percent, 0.15);
  }

  #[test]
  fn test_route_scale_custom() {
    let custom = RouteScale::new(0.5, 0.2, 0.3);
    assert_eq!(custom.scale, 0.5);
    assert_eq!(custom.offset_x_percent, 0.2);
    assert_eq!(custom.offset_y_percent, 0.3);
  }

  #[test]
  fn test_lap_data_position_percentages() {
    let config = LapDataConfig::default();

    // Positions should be between 0.0 and 1.0
    assert!(config.position.0 >= 0.0 && config.position.0 <= 1.0);
    assert!(config.position.1 >= 0.0 && config.position.1 <= 1.0);

    // Calculate pixel positions for 1920x1080
    let x = config.position.0 * 1920.0;
    let y = config.position.1 * 1080.0;

    assert!(x >= 0.0 && x <= 1920.0);
    assert!(y >= 0.0 && y <= 1080.0);
  }

  #[test]
  fn test_pace_dist_config() {
    let default = PaceDistConfig::default();
    assert!(default.show_pace);
    assert!(default.show_distance);

    let pace_only = PaceDistConfig::pace_only();
    assert!(pace_only.show_pace);
    assert!(!pace_only.show_distance);
  }

  #[test]
  fn test_route_video_config_presets() {
    let default = RouteVideoConfig::default();
    assert_eq!(default.show_bottom_bar, true);
    assert_eq!(default.show_route, true);
    assert_eq!(default.show_lap_data, true);
    assert_eq!(
      default.file_config.fit_file,
      "source/example.fit"
    );
    assert_eq!(
      default.file_config.background_image,
      "source/example.jpg"
    );
    assert_eq!(
      default.file_config.output_file,
      "outputs/output.mp4"
    );

    let minimalist = RouteVideoConfig::minimalist();
    assert!(minimalist.show_bottom_bar);

    let neon = RouteVideoConfig::neon();
    assert!(neon.show_route);
  }

  #[test]
  fn test_route_video_config_custom() {
    let file_config = FileConfig::new(
      "test.fit".to_string(),
      "test.jpg".to_string(),
      "test.mp4".to_string(),
    );

    let config = RouteVideoConfig::new(
      RouteScale::new(0.5, 0.1, 0.2),
      RouteColor::default(),
      PaceDistConfig::default(),
      LapDataConfig::default(),
      file_config,
      true,
      false,
      true,
    );

    assert_eq!(config.show_route, false);
    assert_eq!(config.file_config.fit_file, "test.fit");
    assert_eq!(
      config.file_config.background_image,
      "test.jpg"
    );
    assert_eq!(
      config.file_config.output_file,
      "test.mp4"
    );
  }

  #[test]
  fn test_visibility_flags() {
    let mut config = RouteVideoConfig::default();
    config.show_bottom_bar = false;
    config.show_route = false;
    config.show_lap_data = false;

    assert!(!config.show_bottom_bar);
    assert!(!config.show_route);
    assert!(!config.show_lap_data);
  }
}