public static BaseAngle TryParse(string s) { if (s[0] == 'm') { var b = new MilAngle(); b.value = double.Parse(s.Substring(1), NumberFormatInfo.InvariantInfo); return(b); } return(null); }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(DependencyProperty.UnsetValue); } string s = value as string; if (s == "") { return(DependencyProperty.UnsetValue); } BaseAngle val = null; val = DegreeAngle.TryParse(s); if (val == null) { val = RadAngle.TryParse(s); } if (val == null) { val = MilAngle.TryParse(s); } if (val == null) { double d; if (double.TryParse(s, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out d)) { val = BaseAngle.Create <MilAngle>(double.Parse(s, NumberFormatInfo.InvariantInfo)); } } if (val == null) { return(DependencyProperty.UnsetValue); } else { return(val); } }
public static List <FireSolution> CalcFire(Battery battery, MissionSpec mission) { var res = new List <FireSolution>(); var munition = mission.Ammunition; if (munition == null) { return(res); } var rangedata = RangeAzimuthUp(battery, mission); System.Console.WriteLine(rangedata); var range = rangedata.Item1; var azimuth = rangedata.Item2; var up = rangedata.Item3; var deflection = (Math.PI + (azimuth - battery.Dir.RadiansValue)); if (deflection < 0) { deflection = deflection + (2 * Math.PI); } if (deflection > 2 * Math.PI) { deflection = deflection - (2 * Math.PI); } MilAngle m = new MilAngle(); m.RadiansValue = deflection; var rangeArr = new float[] { (float)rangedata.Item1 }; foreach (var rt in munition.Rangetables) { var min = rt.Table.Min(rw => rw.Range); var max = rt.Table.Max(rw => rw.Range); if (min > rangedata.Item1 || max < rangedata.Item1) { res.Add( new FireSolution() { Charge = rt.Charge, Elevation = (min > rangedata.Item1) ? -1 : -2 //-1 = under min range, -2 = over max range } ); continue; } var elev = rt.ElevSpline.Eval(rangeArr); var time = rt.TimeSpline.Eval(rangeArr); //TODO: adjust for height diff var elevAdjust = rt.ElevAdjustSpline.Eval(rangeArr); var timeAdjust = rt.TimeAdjustSpline.Eval(rangeArr); //adjust is per -100 dAlt var elevAdjustVal = elevAdjust[0] * up / -100.0; var timeAdjustVal = timeAdjust[0] * up / -100.0; res.Add(new FireSolution() { Charge = rt.Charge, Deflection = m.InternalValue, Elevation = elev[0] + elevAdjustVal, Time = (int)(time[0] + timeAdjustVal) } ); } return(res); }