Skip to main content

Geofence

Struct Geofence 

Source
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

Source

pub fn new(center: Coordinate, radius_m: f64) -> Self

Creates a fence of radius_m metres around center.

§Arguments
  • center - the middle of the safe area.
  • radius_m - the radius of the safe area in metres; its magnitude is used.
§Returns

A fence that has not yet seen a fix.

Source

pub fn contains(&self, point: Coordinate) -> bool

Returns whether a point lies within the fence.

§Arguments
  • point - the coordinate to test.
§Returns

true if point is on or inside the fence boundary.

Source

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§

Source§

impl Clone for Geofence

Source§

fn clone(&self) -> Geofence

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Geofence

Source§

impl Debug for Geofence

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Geofence

Source§

fn eq(&self, other: &Geofence) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Geofence

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.