Пример #1
0
        private List <OrthogonalLineGrid2D> GetDoors(Vector2Int position, ConfigurationSpaceGrid2D configurationSpace)
        {
            var doors = new List <OrthogonalLineGrid2D>();

            foreach (var doorInfo in configurationSpace.ReverseDoors)
            {
                var line     = doorInfo.Item1;
                var doorLine = doorInfo.Item2;

                var index = line.Contains(position);

                if (index == -1)
                {
                    continue;
                }

                var offset            = line.Length - doorLine.Line.Length;
                var numberOfPositions = Math.Min(Math.Min(offset, Math.Min(index, line.Length - index)), doorLine.Line.Length) + 1;

                if (numberOfPositions == 0)
                {
                    throw new InvalidOperationException();
                }

                for (var i = 0; i < numberOfPositions; i++)
                {
                    var doorStart = doorLine.Line.GetNthPoint(Math.Max(0, index - offset) + i);
                    var doorEnd   = doorStart + doorLine.Length * doorLine.Line.GetDirectionVector();

                    doors.Add(new OrthogonalLineGrid2D(doorStart, doorEnd, doorLine.Line.GetDirection()));
                }
            }

            if (doors.Count == 0)
            {
                throw new InvalidOperationException();
            }

            return(doors);
        }
        public ConfigurationSpaceGrid2D GetConfigurationSpace(TConfiguration configuration1, TConfiguration configuration2)
        {
            // If is over corridor
            if (nodesToCorridorMapping.ContainsKey(new Tuple <TNode, TNode>(configuration1.Room, configuration2.Room)))
            {
                var roomDescription = (RoomDescriptionGrid2D)nodesToCorridorMapping[new Tuple <TNode, TNode>(configuration1.Room, configuration2.Room)];
                var selector        = Tuple.Create(configuration1.RoomShape, configuration2.RoomShape, roomDescription);

                if (corridorToConfigurationSpaceMapping.TryGetValue(selector, out var cachedConfigurationSpace))
                {
                    return(cachedConfigurationSpace);
                }

                var corridorRoomTemplateInstances = roomDescription.RoomTemplates
                                                    .SelectMany(configurationSpacesGenerator.GetRoomTemplateInstances).ToList();

                // var configurationSpace = configurationSpaces.GetConfigurationSpace(configuration1, configuration2);

                var configurationSpace = configurationSpacesGenerator.GetConfigurationSpaceOverCorridors(configuration1.RoomShape, configuration2.RoomShape, corridorRoomTemplateInstances);

                var configurationSpaceNew =
                    new ConfigurationSpaceGrid2D(configurationSpace.Lines, null);
                corridorToConfigurationSpaceMapping[selector] = configurationSpaceNew;

                return(configurationSpaceNew);
            }
            // Otherwise
            else
            {
                var configurationSpace = configurationSpacesGenerator.GetConfigurationSpace(configuration1.RoomShape, configuration2.RoomShape);

                // var configurationSpace = configurationSpaces.GetConfigurationSpace(configuration1, configuration2);

                return(configurationSpace);
            }
        }