use map2fig::cli::TickDirection;
use map2fig::layout::compute_gnomonic_layout;
#[test]
fn test_gnomonic_layout_colorbar_alignment_with_text() {
let map_size = 1200.0;
let show_colorbar = true;
let show_text = true;
let tick_direction = TickDirection::Inward;
let (layout, _cb_layout) = compute_gnomonic_layout(
map_size,
show_colorbar,
tick_direction,
show_text,
true, );
let expected_left_text_pad = 50.0;
let outer_pad = 24.0;
let expected_map_x = outer_pad + expected_left_text_pad;
assert_eq!(
layout.map_x, expected_map_x,
"Map X position should include left_text_pad offset when show_text=true"
);
let expected_cbar_x = outer_pad + expected_left_text_pad;
assert_eq!(
layout.cbar_x, expected_cbar_x,
"Colorbar X position should be aligned with map (shifted by left_text_pad)"
);
assert_eq!(
layout.map_x, layout.cbar_x,
"Map and colorbar should be horizontally aligned when show_text=true"
);
}
#[test]
fn test_gnomonic_layout_colorbar_alignment_without_text() {
let map_size = 1200.0;
let show_colorbar = true;
let show_text = false;
let tick_direction = TickDirection::Inward;
let (layout, _cb_layout) = compute_gnomonic_layout(
map_size,
show_colorbar,
tick_direction,
show_text,
true, );
let outer_pad = 24.0;
let expected_x = outer_pad;
assert_eq!(
layout.map_x, expected_x,
"Map X position should be at outer_pad when show_text=false"
);
assert_eq!(
layout.cbar_x, expected_x,
"Colorbar X position should be at outer_pad when show_text=false"
);
assert_eq!(
layout.map_x, layout.cbar_x,
"Map and colorbar should be aligned when show_text=false"
);
}
#[test]
fn test_gnomonic_layout_map_and_colorbar_always_aligned() {
for show_text in &[true, false] {
for show_colorbar in &[true, false] {
let (layout, _cb_layout) = compute_gnomonic_layout(
1200.0,
*show_colorbar,
TickDirection::Inward,
*show_text,
true, );
assert_eq!(
layout.map_x, layout.cbar_x,
"Map and colorbar should be aligned for show_text={}, show_colorbar={}",
show_text, show_colorbar
);
}
}
}
#[test]
fn test_gnomonic_layout_text_pad_scales_with_map_size() {
let outer_pad = 24.0;
let test_cases = vec![
(600.0, 25.0), (1200.0, 50.0), (2400.0, 100.0), ];
for (map_size, expected_text_pad) in test_cases {
let (layout, _cb_layout) = compute_gnomonic_layout(
map_size,
true,
TickDirection::Inward,
true, true, );
let expected_x = outer_pad * (map_size / 1200.0) + expected_text_pad;
assert!(
(layout.map_x - expected_x).abs() < 0.1,
"At map_size={}, expected map_x={}, got {}",
map_size,
expected_x,
layout.map_x
);
assert_eq!(
layout.map_x, layout.cbar_x,
"Map and colorbar should be aligned at map_size={}",
map_size
);
}
}