Example #1
0
        private (ObjectLocation <StarSystem>, ObjectLocation <StarSystem>) MinDistanceDisconnectedSystemPair(ConnectivityGraph <ObjectLocation <StarSystem> > graph)
        {
            if (graph.Subgraphs.Count() == 0)
            {
                return(null, null);
            }

            (ObjectLocation <StarSystem>, ObjectLocation <StarSystem>)best = (null, null);
            int bestDistance = int.MaxValue;

            if (graph.Subgraphs.Count() == 1)
            {
                foreach (var l1 in graph)
                {
                    foreach (var l2 in graph)
                    {
                        if (graph.AreDirectlyConnected(l1, l2))
                        {
                            continue;
                        }
                        if (IntersectsExceptAtEnds(l1.Location, l2.Location, graph))
                        {
                            continue;
                        }
                        var dist = l1.Location.ManhattanDistance(l2.Location);
                        if (dist < bestDistance && AreWarpPointAnglesOk(l1, l2, Galaxy.Current, MinWarpPointAngle))
                        {
                            bestDistance = dist;
                            best         = (l1, l2);
                        }
                    }
                }
                return(best);
            }

            foreach (var g1 in graph.Subgraphs)
            {
                foreach (var g2 in graph.Subgraphs.ExceptSingle(g1))
                {
                    foreach (var l1 in g1)
                    {
                        foreach (var l2 in g2)
                        {
                            if (graph.AreDirectlyConnected(l1, l2))
                            {
                                continue;
                            }
                            var dist = l1.Location.ManhattanDistance(l2.Location);
                            if (dist < bestDistance && AreWarpPointAnglesOk(l1, l2, Galaxy.Current, MinWarpPointAngle))
                            {
                                bestDistance = dist;
                                best         = (l1, l2);
                            }
                        }
                    }
                }
            }
            return(best);
        }