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 centre 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.
§Arguments
point- the latest fix.
§Returns
Boundary::Entered or Boundary::Exited on the fix that crosses the
boundary, otherwise Boundary::Inside or Boundary::Outside.
Trait Implementations§
impl Copy for Geofence
impl StructuralPartialEq for Geofence
Auto Trait Implementations§
impl Freeze for Geofence
impl RefUnwindSafe for Geofence
impl Send for Geofence
impl Sync for Geofence
impl Unpin for Geofence
impl UnsafeUnpin for Geofence
impl UnwindSafe for Geofence
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more