/// <summary> /// Tests that a point is within the given polygon /// </summary> private static bool IsPointInPolygon(List<Location> poly, Location point) { int i, j; bool c = false; for (i = 0, j = poly.Count - 1; i < poly.Count; j = i++) { if ((((poly[i].Latitude <= point.Latitude) && (point.Latitude < poly[j].Latitude)) || ((poly[j].Latitude <= point.Latitude) && (point.Latitude < poly[i].Latitude))) && (point.Longitude < ((poly[j].Longitude - poly[i].Longitude) * (point.Latitude - poly[i].Latitude) / (poly[j].Latitude - poly[i].Latitude)) + poly[i].Longitude)) c = !c; } return c; }
/// <summary> /// Calculates the standard garbage day (wednesday - friday) for the given location. /// </summary> public static DayOfWeek CalculateGarbageDay(Location location) { if (IsPointInPolygon(WEDNESDAY, location)) return DayOfWeek.Wednesday; else if (IsPointInPolygon(FRIDAY, location)) return DayOfWeek.Friday; return DayOfWeek.Thursday; }