app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 7024032369c96e95661baf4ceb614afcf8bc47e0
parent a75edd7a59b5eb66d261d7c53115b9c434cd31c6
Author: triesap <triesap@radroots.dev>
Date:   Mon, 19 Jan 2026 07:45:30 +0000

app-lib: add geolocation helpers

- add geolocation point struct

- add geolocation init helper

- add geolocation validity helper

- add unit tests for geolocation helpers

Diffstat:
Acrates/app-lib/src/geo.rs | 31+++++++++++++++++++++++++++++++
Mcrates/app-lib/src/lib.rs | 2++
2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/crates/app-lib/src/geo.rs b/crates/app-lib/src/geo.rs @@ -0,0 +1,31 @@ +#![forbid(unsafe_code)] + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct AppGeolocationPoint { + pub lat: f64, + pub lng: f64, +} + +pub fn geop_is_valid(point: Option<AppGeolocationPoint>) -> bool { + if let Some(point) = point { + !(point.lat == 0.0 && point.lng == 0.0) + } else { + false + } +} + +pub fn geop_init() -> AppGeolocationPoint { + AppGeolocationPoint { lat: 0.0, lng: 0.0 } +} + +#[cfg(test)] +mod tests { + use super::{geop_init, geop_is_valid, AppGeolocationPoint}; + + #[test] + fn geop_is_valid_checks_coords() { + assert!(!geop_is_valid(None)); + assert!(!geop_is_valid(Some(geop_init()))); + assert!(geop_is_valid(Some(AppGeolocationPoint { lat: 1.0, lng: 1.0 }))); + } +} diff --git a/crates/app-lib/src/lib.rs b/crates/app-lib/src/lib.rs @@ -1,5 +1,7 @@ #![forbid(unsafe_code)] pub mod browser; +pub mod geo; pub use browser::{browser_platform, BrowserPlatformInfo}; +pub use geo::{geop_init, geop_is_valid, AppGeolocationPoint};