public static void LoadCharts() { try { listCharts = new List <Chart>(); StreamReader file = File.OpenText(MultiOSFileSupport.ResourcesFolder + "charts.json"); StringBuilder jsonstring = new StringBuilder(); while (file.Peek() >= 0) { jsonstring.Append(file.ReadLine()); } var listCountires = JsonConvert.DeserializeObject <IDictionary <string, IDictionary <string, string> > >(jsonstring.ToString()); foreach (var item in listCountires) { var chart = new Chart() { Name = item.Key, Region = item.Value["Region"], ChartType = (item.Value["Type"] == "STAR") ? ChartType.Star : ChartType.SID, CheckPoints = new List <CheckPoint>(), Doors = new List <CheckPoint>() }; List <string> doors = item.Value["Doors"].Split(';').ToList(); List <string> checkpoints = item.Value["CheckPoints"].Split(';').ToList(); for (int i = 0; i < doors.Count; i++) { var chk = CheckPoint.GetCheckPoint(doors[i]); if (chk != null) { chart.Doors.Add(chk); } } for (int i = 0; i < checkpoints.Count; i++) { var chk = CheckPoint.GetCheckPoint(checkpoints[i]); if (chk != null) { chart.CheckPoints.Add(chk); } } listCharts.Add(chart); } } catch (Exception e) { throw new ArgumentException(MultiOSFileSupport.ResourcesFolder + "charts.json"); } }
public static bool IsInsideAngle(double targetLongitude, double targetLatitude, double targetDirection, CheckPoint point1, CheckPoint point2) { return(IsInsideAngle(targetLongitude, targetLatitude, targetDirection, point1, point2, true)); }
public static bool IsInsideAngle(double targetLongitude, double targetLatitude, CheckPoint point1, CheckPoint point2) { return(IsInsideAngle(targetLongitude, targetLatitude, 0, point1, point2, false)); }
private static bool IsInsideAngle(double targetLongitude, double targetLatitude, double targetDirection, CheckPoint point1, CheckPoint point2, bool mustHaveDirection) { bool result = false; double degreesAperture = 3; double degreesOne = GetAngle(point1.Longitude, point2.Longitude, point1.Latitude, point2.Latitude); double degreesTwo = GetAngle(point2.Longitude, point1.Longitude, point2.Latitude, point1.Latitude); double degreesOneFromPosition = GetAngle(point1.Longitude, targetLongitude, point1.Latitude, targetLatitude); double degreesTwoFromPosition = GetAngle(point2.Longitude, targetLongitude, point2.Latitude, targetLatitude); bool isTargetInAngleFromOne = degreesOne - degreesAperture <degreesOneFromPosition && degreesOne + degreesAperture> degreesOneFromPosition || degreesTwo - degreesAperture <degreesTwoFromPosition && degreesTwo + degreesAperture> degreesTwoFromPosition; bool targetCompatibleHasAngle = targetDirection - degreesAperture <degreesOneFromPosition && targetDirection + degreesAperture> degreesOneFromPosition || targetDirection - degreesAperture <degreesTwoFromPosition && targetDirection + degreesAperture> degreesTwoFromPosition; if (isTargetInAngleFromOne && targetCompatibleHasAngle && mustHaveDirection) { result = true; } else if (isTargetInAngleFromOne && !mustHaveDirection) { result = true; } return(result); }