sparser data transfers

This commit is contained in:
vcoppe committed 2026-10-18 12:35:32 +02:00
1 parent 48325e6016
commit 4583874e7e
23 files changed
+509 -229

No files matched your search

+13 -10
View File
@@ -26,8 +26,6 @@ stats_getter!(total_distance, Float64Array);
stats_getter!(elevation_gain, Float64Array);
stats_getter!(elevation_loss, Float64Array);
stats_getter!(slope, Float64Array);
stats_getter!(slope_segment_slope, Float64Array);
stats_getter!(slope_segment_distance, Float64Array);
stats_getter!(lng, Float64Array);
stats_getter!(lat, Float64Array);
stats_getter!(ele, Float64Array);
@@ -49,14 +47,6 @@ optional_stats_getter!(moving_distance, Float64Array);
optional_stats_getter!(total_time, BigInt64Array);
optional_stats_getter!(moving_time, BigInt64Array);
optional_stats_getter!(speed, Float64Array);
// Timestamps in milliseconds since the epoch (`NO_TIME`, the smallest i64, when missing).
optional_stats_getter!(timestamps, BigInt64Array);
/// Value of the timestamps of the trackpoints that have none.
#[wasm_bindgen]
pub fn no_time() -> i64 {
gpx_engine::NO_TIME
}
optional_stats_getter!(hr, Float64Array);
optional_stats_getter!(cad, Float64Array);
@@ -96,6 +86,19 @@ categories_getters!(highway_starts, highway_values, highways);
categories_getters!(sac_scale_starts, sac_scale_values, sac_scales);
categories_getters!(mtb_scale_starts, mtb_scale_values, mtb_scales);
// The smoothed elevation segments of the selection, over which the slope is averaged, as
// intervals of trackpoints: `slope_segment_starts` holds the index of the first trackpoint of each
// segment, and `slope_segment_slopes` its slope (%). Their length is in `selection_point`.
stats_getter!(slope_segment_starts, Uint32Array);
stats_getter!(slope_segment_slopes, Float64Array);
/// What the buffers do not hold for each trackpoint of the selection, for the one at `index`
/// (numbered as in the buffers), `undefined` if there is none.
#[wasm_bindgen]
pub fn selection_point(index: usize) -> SelectionPoint {
optional_js(with_engine(|e| api::selection_point(e, index)).flatten()).unchecked_into()
}
/// For each trackpoint of the selection (numbered as in the statistics), the highest tolerance
/// (m) of `reduce` that keeps it: infinite for the ends of the segments.
#[wasm_bindgen]
+15 -4
View File
@@ -4,7 +4,7 @@
#![allow(clippy::needless_borrows_for_generic_args)]
use js_sys::{Array, BigInt64Array, Float64Array, Object, Reflect};
use js_sys::{Array, Float64Array, Object, Reflect};
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
@@ -144,7 +144,10 @@ fn test_loaded_file_has_statistics_and_coordinates() {
assert_eq!(crate::queries::statistics::lng().length(), n);
assert_eq!(crate::queries::statistics::ele().length(), n);
// no timestamps in this file
assert!(crate::queries::statistics::timestamps().is_none());
let point = crate::queries::statistics::selection_point(0);
assert!(get(&point, "slopeSegmentDistance").as_f64().is_some());
assert!(get(&point, "time").is_undefined());
assert!(crate::queries::statistics::selection_point(n as usize).is_undefined());
let structure = crate::queries::files::file_structure(&id);
let segment = get(
@@ -165,8 +168,8 @@ fn test_loaded_file_has_statistics_and_coordinates() {
#[wasm_bindgen_test]
fn test_timestamps_and_categories() {
started_with(&[(WITH_TIME, "time")]);
let times: BigInt64Array = crate::queries::statistics::timestamps().unwrap();
assert!(times.length() > 0);
let point = crate::queries::statistics::selection_point(0);
assert!(get(&point, "time").as_f64().unwrap() > 0.0);
assert!(crate::queries::statistics::total_time().is_some());
started_with(&[(WITH_SURFACE, "surface")]);
@@ -179,6 +182,14 @@ fn test_timestamps_and_categories() {
crate::queries::statistics::surface_starts().length(),
values.len() as u32
);
// the name of the surface of a trackpoint that has one
let starts = crate::queries::statistics::surface_starts().to_vec();
let known = values.iter().position(|v| *v > 0).unwrap();
let point = crate::queries::statistics::selection_point(starts[known] as usize);
assert_eq!(
get(&point, "surface").as_string(),
Some(surfaces[values[known] as usize - 1].clone())
);
}
#[wasm_bindgen_test]
+17
View File
@@ -64,6 +64,21 @@ export interface TrackpointDetails {
/** ms since epoch */
time?: number;
}
/**
* A trackpoint of the selection: what the statistics buffers do not hold for each trackpoint.
* Absent fields are unknown.
*/
export interface SelectionPoint {
/** ms since epoch */
time?: number;
/** Slope (%) and length (km) of the smoothed elevation segment of the trackpoint. */
slopeSegmentSlope?: number;
slopeSegmentDistance?: number;
surface?: string;
highway?: string;
sacScale?: string;
mtbScale?: string;
}
/** What was copied or cut, to be pasted: the kind of the elements and their ids. */
export interface Clipboard {
type: 'files' | 'tracks' | 'segments' | 'waypoints';
@@ -161,6 +176,8 @@ extern "C" {
pub type WaypointDetails;
#[wasm_bindgen(typescript_type = "TrackpointDetails | undefined")]
pub type TrackpointDetails;
#[wasm_bindgen(typescript_type = "SelectionPoint | undefined")]
pub type SelectionPoint;
#[wasm_bindgen(typescript_type = "MoveTarget")]
pub type MoveTarget;