From 3498fe5ae3b5343ff7e35a1ef0ef294d1921e929 Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Sun, 13 Nov 2022 14:19:07 +0100 Subject: [PATCH] Changed protection of Graph.nodes to private --- Executable/Program.cs | 4 ++-- Graph/Graph.cs | 12 +++++++++++- OpenStreetMap Importer/Importer.cs | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Executable/Program.cs b/Executable/Program.cs index 9d94fe1..03dfbcb 100644 --- a/Executable/Program.cs +++ b/Executable/Program.cs @@ -13,8 +13,8 @@ do { do { - n1 = graph.nodes[r.Next(0, graph.nodes.Count - 1)]; - n2 = graph.nodes[r.Next(0, graph.nodes.Count - 1)]; + n1 = graph.GetNodeAtIndex(r.Next(0, graph.GetNodeCount() - 1)); + n2 = graph.GetNodeAtIndex(r.Next(0, graph.GetNodeCount() - 1)); _route = new Astar().FindPath(graph, n1, n2, logger); } while (!_route.routeFound); } while (Console.ReadKey().Key.Equals(ConsoleKey.Enter)); \ No newline at end of file diff --git a/Graph/Graph.cs b/Graph/Graph.cs index 74fa14f..8ec209e 100644 --- a/Graph/Graph.cs +++ b/Graph/Graph.cs @@ -3,7 +3,7 @@ namespace Graph { public class Graph { - public List nodes { get; } + private List nodes { get; } public Graph() { @@ -23,6 +23,16 @@ namespace Graph } } + public Node GetNodeAtIndex(int i) + { + return this.nodes[i]; + } + + public int GetNodeCount() + { + return this.nodes.Count; + } + public Node? GetNode(ulong id) { foreach(Node n in this.nodes) diff --git a/OpenStreetMap Importer/Importer.cs b/OpenStreetMap Importer/Importer.cs index f983c16..4e9b9f6 100644 --- a/OpenStreetMap Importer/Importer.cs +++ b/OpenStreetMap Importer/Importer.cs @@ -34,7 +34,7 @@ namespace OpenStreetMap_Importer mapData.Position = 0; logger?.Log(LogLevel.INFO, "Importing Graph..."); Graph.Graph _graph = CreateGraph(mapData, occuranceCount, onlyJunctions, logger); - logger?.Log(LogLevel.DEBUG, "Loaded Nodes: {0}", _graph.nodes.Count); + logger?.Log(LogLevel.DEBUG, "Loaded Nodes: {0}", _graph.GetNodeCount()); mapData.Close(); occuranceCount.Clear();