public bool enclose(Vertex point, double margin, bool logDetails = false) { var res = MkGeoAlgo.isInside(this, point, 2 * margin); // print(JSON.json(res, 2)) if (logDetails && null != geoFenceLogger) { bool hasIn = false; bool hasBorder = false; geoFenceLogger("________________"); geoFenceLogger($"point ({point.x}, {point.y}): "); if (res.ContainsKey("in")) { geoFenceLogger($" is inside {res["in"][0].name}"); hasIn = true; } if (res.ContainsKey("border")) { geoFenceLogger($" is on the border of {res["border"][0].name}"); hasBorder = true; } if (!(hasIn || hasBorder)) { geoFenceLogger(" is outside the map of this GeoPoly"); } if (res.ContainsKey("buffer")) { geoFenceLogger($" is within the buffer of these regions: "); foreach (var b in res["buffer"]) { geoFenceLogger($" ({b.name}, {b.buffer})"); } } geoFenceLogger("^^^^^^^^^^^^^^^"); } if (res.ContainsKey("in") || res.ContainsKey("border")) { return(true); } else if (res.ContainsKey("buffer")) { foreach (var b in res["buffer"]) { if (Math.Abs(b.buffer) <= margin) { return(true); } } } return(false); }
public double distanceToBorder(Vertex point, double radiusOfInterest) { LinearRing outerRing = this.polygon.outerRing; var res = MkGeoAlgo.isInside(point, this.polygon.outerRing, radiusOfInterest); double ret = res.radius; if (res.inout == 0) { ret = 0.0; } else if (res.inout < 0) { // inside if (res.radius > 0.0) { // This should not happen, but we log and trim it. string err = $"Inside the ring but buffer {res.radius} > 0! {point.x} , {point.y}, {res.inout}"; if (DEBUG) { throw new Exception(err); } else if (geoFenceLogger != null) { geoFenceLogger(err); } ret = 0.0; } } else { // res.inout > 0 if (res.radius < 0.0) { // This should not happen, but we log and trim it. string err = $"Outside the ring but buffer {res.radius} < 0! {point.x} , {point.y}, {res.inout}"; if (DEBUG) { throw new Exception(err); } else if (geoFenceLogger != null) { geoFenceLogger(err); } ret = 0.0; } } return(ret); }