mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-09 23:26:31 +00:00
refactoring and tests
This commit is contained in:
1 parent
3bb553d6b5
commit
da9abbae5e
45 files changed
+3558
-1564
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import type { SelectMode } from './types';
|
||||
|
||||
export type Wasm = typeof import('gpx-rs');
|
||||
|
||||
/** The enumeration of the engine for a way to combine a selection. */
|
||||
export function selectMode(wasm: Wasm, mode: SelectMode) {
|
||||
return {
|
||||
replace: wasm.SelectMode.Replace,
|
||||
add: wasm.SelectMode.Add,
|
||||
toggle: wasm.SelectMode.Toggle,
|
||||
}[mode];
|
||||
}
|
||||
|
||||
/** A flat `[lng, lat, ...]` array as positions. */
|
||||
export function toPositions(flat: Float64Array): [number, number][] {
|
||||
const positions: [number, number][] = new Array(flat.length / 2);
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
positions[i] = [flat[2 * i], flat[2 * i + 1]];
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
export /** Hyphenated UUID strings (as found in the file structures) to the concatenated 16-byte form. */
|
||||
function idsToBytes(ids: string[]): Uint8Array {
|
||||
const bytes = new Uint8Array(ids.length * 16);
|
||||
ids.forEach((id, i) => {
|
||||
const hex = id.replaceAll('-', '');
|
||||
for (let j = 0; j < 16; j++) {
|
||||
bytes[i * 16 + j] = parseInt(hex.slice(2 * j, 2 * j + 2), 16);
|
||||
}
|
||||
});
|
||||
return bytes;
|
||||
}
|
||||
Reference in new issue
Block a user