public MainWindow(ILogger <MainWindow> logger, IFlightConnector flightConnector, MainViewModel viewModel, IOptionsMonitor <AppSettings> appSettings, DiscordRichPresentLogic discordRichPresentLogic, ATCServer atcServer, UserPreferencesLoader userPreferencesLoader, VersionLogic versionLogic, UdpBroadcastLogic udpBroadcastLogic) { InitializeComponent(); this.logger = logger; this.flightConnector = flightConnector; this.atcServer = atcServer; this.userPreferencesLoader = userPreferencesLoader; this.versionLogic = versionLogic; this.udpBroadcastLogic = udpBroadcastLogic; this.viewModel = viewModel; this.discordRichPresentLogic = discordRichPresentLogic; this.appSettings = appSettings.CurrentValue; this.lineSimplifier = new LineSimplifier(); flightConnector.AircraftStatusUpdated += FlightConnector_AircraftStatusUpdated; flightConnector.AircraftPositionChanged += FlightConnector_AircraftPositionChanged; flightConnector.AirportListReceived += FlightConnector_AirportListReceived; flightConnector.Error += FlightConnector_Error; DataContext = viewModel; }
public async Task TestImprovement() { var lineSimplifier = new LineSimplifier(); await TestAsync(lineSimplifier, "../../../route.json"); await TestAsync(lineSimplifier, "../../../route2.json"); }
/// <summary> /// Mark a line as complete and remove it from the incubator. /// </summary> /// <param name="lineId">The id of the line to complete.</param> /// <returns>The completed line.</returns> public DrawnLine CompleteLine(string lineId) { if (!currentLines.ContainsKey(lineId)) { throw new KeyNotFoundException("Error: A line with that id wasn't found in this LineIncubator."); } DrawnLine completedLine = currentLines[lineId]; currentLines.Remove(lineId); int originalPointCount = completedLine.Points.Count; completedLine.Points = LineSimplifier.SimplifyLine(completedLine.Points, 6); Log.WriteLine( "[LineIncubator] [LineComplete] #{0}: {1} -> {2} points ({3:0.00}% reduction)", lineId, originalPointCount, completedLine.Points.Count, ((float)completedLine.Points.Count / (float)originalPointCount) * 100f ); return(completedLine); }
private static async Task TestAsync(LineSimplifier lineSimplifier, string path) { var route = JsonConvert.DeserializeObject <List <AircraftStatusBrief> >(await File.ReadAllTextAsync(Path.Combine(Directory.GetCurrentDirectory(), path))); for (var t = 0.0001; t < 0.001; t += 0.0001) { var simplifiedRoute = lineSimplifier.DouglasPeucker(route, t).ToList(); Debug.WriteLine($"Tolerant: {t}. Original: {route.Count}. Simplified: {simplifiedRoute.Count}."); Assert.IsTrue(route.Count > simplifiedRoute.Count); } }