pub struct Geofence { /* private fields */ }Expand description
Keeping a tracked point inside an area, and noticing when it leaves.
This is the primitive behind “tell me when it leaves the safe zone”: a collared
animal straying from its pasture, an asset moving off-site, or a drone crossing
its allowed boundary. A fence is a center and a radius; feeding it successive
fixes reports whether each is Inside or
Outside and, crucially, the single fix that
Exited or Entered, so an alert fires
once on the crossing rather than on every fix while away.
§Examples
use pamoja_kit::{Boundary, Coordinate, Geofence};
// A 50 m pen around the waterpoint; the collar fix then wanders out.
let mut pen = Geofence::new(Coordinate::new(-1.2921, 36.8219), 50.0);
assert_eq!(pen.update(Coordinate::new(-1.2921, 36.8219)), Boundary::Inside);
assert_eq!(pen.update(Coordinate::new(-1.2930, 36.8219)), Boundary::Exited);Implementations§
Source§impl Geofence
impl Geofence
Sourcepub fn new(center: Coordinate, radius_m: f64) -> Self
pub fn new(center: Coordinate, radius_m: f64) -> Self
Sourcepub fn contains(&self, point: Coordinate) -> bool
pub fn contains(&self, point: Coordinate) -> bool
Sourcepub fn update(&mut self, point: Coordinate) -> Boundary
pub fn update(&mut self, point: Coordinate) -> Boundary
Records a fix and reports its position relative to the fence.
A fix whose latitude or longitude is not a finite number, which a receiver without a
lock can report, is no fix: it changes nothing and reports the state as it stood,
Boundary::Outside before any real fix, and never an exit or an entry.
§Arguments
point- the latest fix.
§Returns
Boundary::Entered or Boundary::Exited on the fix that crosses the
boundary, otherwise Boundary::Inside or Boundary::Outside.