Ejemplo n.º 1
0
        public static SectorGraph BuildFrom(MapData map)
        {
            var linesWithVertices = BuildLinesWithStartingVertex(map);

            List <LogicalSector> logicalSectors = new List <LogicalSector>();
            List <SubSector>     subSectors     = new List <SubSector>();

            foreach (var lineGroup in linesWithVertices.GroupBy(pair => pair.Line.Side.Sector).OrderBy(g => g.Key))
            {
                var sector        = map.Sectors[lineGroup.Key];
                var logicalSector = new LogicalSector(lineGroup.Key, sector);

                var sectorLines = new LinkedList <LineAndVertices>(lineGroup);

                while (sectorLines.Any())
                {
                    var(startVertexId, lastVertexId, line) = sectorLines.TakeFirst();

                    var subSectorLines = new List <Line> {
                        line
                    };

                    while (sectorLines.Any() && lastVertexId != startVertexId)
                    {
                        (_, lastVertexId, line) = sectorLines.TakeFirst(pair => pair.StartVertexId == lastVertexId);

                        subSectorLines.Add(line);
                    }

                    var ss = new SubSector(lineGroup.Key, logicalSector, subSectorLines);
                    logicalSector.Add(ss);
                    subSectors.Add(ss);
                }
                logicalSectors.Add(logicalSector);
            }

            return(new SectorGraph(map, logicalSectors, subSectors));
        }
Ejemplo n.º 2
0
 public SubSector(int sectorIndex, LogicalSector parent, IEnumerable <Line> lines)
 {
     SectorIndex  = sectorIndex;
     ParentSector = parent;
     _lines.AddRange(lines);
 }