Beispiel #1
0
        public static RoomTemplate ToOldRoomTemplate(this RoomTemplateGrid2D roomTemplate)
        {
            var       doorMode    = roomTemplate.Doors;
            IDoorMode oldDoorMode = null;

            if (roomTemplate.RepeatMode == null)
            {
                throw new NotSupportedException("Null repeat mode is currently not supported");
            }

            if (doorMode is SimpleDoorModeGrid2D simpleDoorMode)
            {
                if (simpleDoorMode.DoorSocket != null)
                {
                    throw new NotSupportedException("Old room templates support only null sockets");
                }

                oldDoorMode = new SimpleDoorMode(simpleDoorMode.DoorLength, simpleDoorMode.CornerDistance);
            }
            else if (doorMode is ManualDoorModeGrid2D manualDoorMode)
            {
                if (manualDoorMode.Doors.Any(x => x.Socket != null))
                {
                    throw new NotSupportedException("Old room templates support only null sockets");
                }

                oldDoorMode = new ManualDoorMode(manualDoorMode.Doors.Select(x => new OrthogonalLineGrid2D(x.From, x.To)).ToList());
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            return(new RoomTemplate(roomTemplate.Outline, oldDoorMode, roomTemplate.AllowedTransformations, roomTemplate.RepeatMode.Value, roomTemplate.Name));
        }
        /// <summary>
        /// Computes configuration space of given two polygons.
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="doorsMode"></param>
        /// <param name="fixedCenter"></param>
        /// <param name="fixedDoorsMode"></param>
        /// <param name="offsets"></param>
        /// <returns></returns>
        public ConfigurationSpace GetConfigurationSpace(GridPolygon polygon, IDoorMode doorsMode, GridPolygon fixedCenter,
                                                        IDoorMode fixedDoorsMode, List <int> offsets = null)
        {
            var doorLinesFixed = doorHandler.GetDoorPositions(fixedCenter, fixedDoorsMode);
            var doorLines      = doorHandler.GetDoorPositions(polygon, doorsMode);

            return(GetConfigurationSpace(polygon, doorLines, fixedCenter, doorLinesFixed, offsets));
        }
Beispiel #3
0
        /// <inheritdoc />
        /// <remarks>
        /// Gets door positions by by returning an output of a registered door handler.
        /// </remarks>
        /// <param name="polygon"></param>
        /// <param name="doorMode"></param>
        /// <returns></returns>
        public List <DoorLine> GetDoorPositions(PolygonGrid2D polygon, IDoorMode doorMode)
        {
            if (handlers.TryGetValue(doorMode.GetType(), out var handler))
            {
                return(handler.GetDoorPositions(polygon, doorMode));
            }

            throw new InvalidOperationException("Handler not found");
        }
 public RoomTemplate(PolygonGrid2D shape, IDoorMode doorsMode, List <TransformationGrid2D> allowedTransformations = null, RoomTemplateRepeatMode repeatMode = RoomTemplateRepeatMode.AllowRepeat, string name = null)
 {
     Shape     = shape;
     DoorsMode = doorsMode;
     AllowedTransformations = allowedTransformations ?? new List <TransformationGrid2D>()
     {
         TransformationGrid2D.Identity
     };
     RoomTemplateRepeatMode = repeatMode;
     Name = name ?? "Room template";
 }
Beispiel #5
0
        public ConfigurationSpace GetConfigurationSpaceOverCorridor(PolygonGrid2D polygon, IDoorMode doorsMode,
                                                                    PolygonGrid2D fixedPolygon, IDoorMode fixedDoorsMode, PolygonGrid2D corridor,
                                                                    IDoorMode corridorDoorsMode)
        {
            var doorLines         = doorHandler.GetDoorPositions(polygon, doorsMode);
            var doorLinesFixed    = doorHandler.GetDoorPositions(fixedPolygon, fixedDoorsMode);
            var doorLinesCorridor = doorHandler.GetDoorPositions(corridor, corridorDoorsMode);

            return(GetConfigurationSpaceOverCorridor(polygon, doorLines, fixedPolygon, doorLinesFixed, corridor,
                                                     doorLinesCorridor));
        }
Beispiel #6
0
        /// <inheritdoc />
        /// <remarks>
        /// Checks if all positions are contained on one of polygon's sides.
        /// Changes direction if needed.
        /// </remarks>
        public List <IDoorLine> GetDoorPositions(GridPolygon polygon, IDoorMode doorModeRaw)
        {
            if (!(doorModeRaw is SpecificPositionsMode doorMode))
            {
                throw new InvalidOperationException("Invalid door mode supplied");
            }

            var doors = new List <IDoorLine>();

            foreach (var doorPosition in doorMode.DoorPositions)
            {
                doors.Add(GetDoorLine(polygon, doorPosition));
            }

            return(doors);
        }
        /// <inheritdoc />
        public List <IDoorLine> GetDoorPositions(GridPolygon polygon, IDoorMode doorModeRaw)
        {
            if (!(doorModeRaw is OverlapMode doorMode))
            {
                throw new InvalidOperationException("Invalid door mode supplied");
            }

            var lines = new List <IDoorLine>();

            foreach (var line in polygon.GetLines())
            {
                if (line.Length < 2 * doorMode.CornerDistance + doorMode.DoorLength)
                {
                    continue;
                }

                lines.Add(new DoorLine(line.Shrink(doorMode.CornerDistance, doorMode.CornerDistance + doorMode.DoorLength), doorMode.DoorLength));
            }

            return(lines);
        }
        /// <inheritdoc />
        /// <remarks>
        /// Checks if all positions are contained on one of polygon's sides.
        /// Changes direction if needed.
        /// </remarks>
        public List <IDoorLine> GetDoorPositions(GridPolygon polygon, IDoorMode doorModeRaw)
        {
            if (!(doorModeRaw is SpecificPositionsMode doorMode))
            {
                throw new InvalidOperationException("Invalid door mode supplied");
            }

            if (doorMode.DoorPositions.Distinct().Count() != doorMode.DoorPositions.Count)
            {
                throw new ArgumentException("All door positions must be unique");
            }

            var doors = new List <IDoorLine>();

            foreach (var doorPosition in doorMode.DoorPositions)
            {
                doors.AddRange(GetDoorLine(polygon, doorPosition));
            }

            return(doors);
        }
Beispiel #9
0
        /// <inheritdoc />
        /// <remarks>
        /// Checks if all positions are contained on one of polygon's sides.
        /// Changes direction if needed.
        /// </remarks>
        public List <DoorLine> GetDoorPositions(PolygonGrid2D polygon, IDoorMode doorMode)
        {
            if (!(doorMode is ManualDoorMode manualDoorMode))
            {
                throw new InvalidOperationException("Invalid door mode supplied");
            }

            if (manualDoorMode.DoorPositions.Distinct().Count() != manualDoorMode.DoorPositions.Count)
            {
                throw new ArgumentException("All door positions must be unique");
            }

            var doors = new List <DoorLine>();

            foreach (var doorPosition in manualDoorMode.DoorPositions)
            {
                doors.AddRange(GetDoorLine(polygon, doorPosition));
            }

            return(doors);
        }
 public RoomDescription(GridPolygon shape, IDoorMode doorsMode)
 {
     Shape     = new GridPolygon(shape.GetPoints());
     DoorsMode = doorsMode;
 }