Files
gpx.studio/gpx-rs/src/algorithm/smooth.rs
T

51 lines
1.6 KiB
Rust
Raw Normal View History

2026-09-21 23:49:57 +02:00
#[macro_export]
macro_rules! for_each_window {
(
2026-09-23 19:53:39 +02:00
$trkseg:expr,
2026-09-21 23:49:57 +02:00
$left:expr,
$right:expr,
$window:expr,
|$a:ident, $b:ident| $distance:expr,
|$i:ident, $l:ident, $r:ident| $body:block,
) => {{
2026-10-02 18:06:45 +02:00
let mut window_start = $left.unwrap_or_default();
let mut window_center = $left;
let mut window_end = $left.unwrap_or_default();
while let Some(idx) = window_center {
2026-09-23 19:53:39 +02:00
// advance left if needed
2026-10-02 18:06:45 +02:00
while window_start != idx && {
let $a = window_start;
2026-09-23 19:53:39 +02:00
let $b = idx;
2026-09-21 23:49:57 +02:00
$distance
2026-09-23 19:53:39 +02:00
} > $window {
2026-10-02 18:06:45 +02:00
if let Some(next) = $trkseg.next_index(Some(window_start)) {
2026-09-23 19:53:39 +02:00
if next == idx {
break;
}
2026-10-02 18:06:45 +02:00
window_start = next;
2026-09-23 19:53:39 +02:00
} else {
break;
}
2026-09-21 23:49:57 +02:00
}
2026-09-23 19:53:39 +02:00
// advance right if needed
2026-10-02 18:06:45 +02:00
window_end = window_end.max(idx);
while let Some(next) = $trkseg.next_index(Some(window_end)) {
if window_end != idx && {
2026-09-23 19:53:39 +02:00
let $a = idx;
2026-10-02 18:06:45 +02:00
let $b = next;
2026-09-23 19:53:39 +02:00
$distance
} > $window {
break;
}
2026-10-02 18:06:45 +02:00
window_end = next;
2026-09-21 23:49:57 +02:00
}
2026-09-23 19:53:39 +02:00
// apply body
let $i = idx;
2026-10-02 18:06:45 +02:00
let $l = window_start;
let $r = window_end;
2026-09-21 23:49:57 +02:00
$body
2026-09-23 19:53:39 +02:00
// go next
2026-10-02 18:06:45 +02:00
window_center = $trkseg.next_index(window_center);
2026-09-21 23:49:57 +02:00
}
}};
}