Skip to content

Commit

Permalink
add geofence
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbo committed Oct 8, 2020
1 parent eb0addd commit 39c9602
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
11 changes: 9 additions & 2 deletions esp_server/wifiLocalization/ConnectionManager/DBConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,15 @@ public List<DatiDispositivo> GetLastMinuteData(int nBoards, int threshold = 0)
Punto point = Cerchio.Intersezione(cerchi);
if(!(Double.IsNaN(point.Ascissa) || Double.IsNaN(point.Ordinata)))
{
DatiDispositivo p = new DatiDispositivo(mac, timestamp, point, global);
list.Add(p);
if (point.isInside(schede))
{
DatiDispositivo p = new DatiDispositivo(mac, timestamp, point, global);
list.Add(p);
}
else
{
System.Diagnostics.Debug.WriteLine("Geofence discarded: (" + point.Ascissa + "; " + point.Ordinata + ")");
}
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion esp_server/wifiLocalization/Utilities/Punto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace WifiLocalization.Utilities
using System;
using System.Collections.Concurrent;

namespace WifiLocalization.Utilities
{
public class Punto
{
Expand All @@ -17,6 +20,35 @@ public Punto(double x, double y)
Ordinata = y;
}

public bool isInside(ConcurrentDictionary<int, Scheda> schede)
{
double x_max = Double.MinValue;
double y_max = Double.MinValue;
double x_min = Double.MaxValue;
double y_min = Double.MaxValue;
foreach (Scheda scheda in schede.Values)
{
if (scheda.Punto.Ascissa > x_max)
x_max = scheda.Punto.Ascissa;
if (scheda.Punto.Ascissa < x_min)
x_min = scheda.Punto.Ascissa;
if (scheda.Punto.Ordinata > y_max)
y_max = scheda.Punto.Ordinata;
if (scheda.Punto.Ordinata < y_min)
y_min = scheda.Punto.Ordinata;
}

if (Ascissa < x_min)
return false;
if (Ascissa > x_max)
return false;
if (Ordinata < y_min)
return false;
if (Ordinata > y_max)
return false;
return true;
}

public static bool operator == (Punto a, Punto b)
{
return Equals(a, b);
Expand Down

0 comments on commit 39c9602

Please sign in to comment.