public void OverlapArea_NonTouching_ReturnsZero()
        {
            var r1 = GridPolygon.GetSquare(6);
            var r2 = GridPolygon.GetRectangle(2, 8);

            Assert.AreEqual(0, polygonOverlap.OverlapArea(r1, new IntVector2(0, 0), r2, new IntVector2(7, 2)));
        }
        public void OverlapArea_TwoRectangles()
        {
            var r1 = GridPolygon.GetRectangle(4, 6);
            var r2 = GridPolygon.GetRectangle(5, 3);

            Assert.AreEqual(9, polygonOverlap.OverlapArea(r1, new IntVector2(0, 0), r2, new IntVector2(1, 2)));
        }
		public MapDescription<int> GetMapDescription()
		{
			var mapDescription = new MapDescription<int>();
			mapDescription.SetupWithGraph(GraphsDatabase.GetExample5());

			// Add room shapes
			var doorMode = new OverlapMode(1, 1);

			var squareRoomBig = new RoomDescription(
				GridPolygon.GetSquare(8),
				doorMode
			);
			var squareRoomSmall = new RoomDescription(
				GridPolygon.GetSquare(6),
				doorMode
			);
			var rectangleRoomBig = new RoomDescription(
				GridPolygon.GetRectangle(8, 12),
				doorMode
			);
			var rectangleRoomSmall = new RoomDescription(
				GridPolygon.GetRectangle(6, 10),
				doorMode
			);

			mapDescription.AddRoomShapes(squareRoomBig, probability: 10);
			mapDescription.AddRoomShapes(squareRoomSmall);
			mapDescription.AddRoomShapes(rectangleRoomBig);
			mapDescription.AddRoomShapes(rectangleRoomSmall);

			return mapDescription;
		}
Пример #4
0
        public void TransformPointToNewPosition_RectanglePoints()
        {
            // Create a rectangular room shape
            // Move it away from (0, 0) so that we can properly test the functionality
            var rectangleShape = GridPolygon.GetRectangle(10, 4) + new IntVector2(10, 10);

            // Create points to be transformed
            // These could be for example traps, spawn points, etc.
            // We use points of the rectangle here because it is easy to check that the transformation is correct.
            var pointsToTransform = rectangleShape.GetPoints();

            var mapDescription = new MapDescription <int>();

            // Create simple graph with 2 vertices and 1 edge
            mapDescription.AddRoom(0);
            mapDescription.AddRoom(1);
            mapDescription.AddPassage(0, 1);

            // Add the rectangle shape
            mapDescription.AddRoomShapes(new RoomDescription(rectangleShape, new OverlapMode(1, 0)));

            var layoutGenerator = LayoutGeneratorFactory.GetDefaultChainBasedGenerator <int>();
            var layout          = layoutGenerator.GetLayouts(mapDescription, 1)[0];

            foreach (var room in layout.Rooms)
            {
                // The points were chosen to be the points of the polygon, so after transforming them, they should
                // be equal to the room.Shape + room.Position points
                var transformedPoints = pointsToTransform.Select(x => room.TransformPointToNewPosition(x));
                var expectedPoints    = (room.Shape + room.Position).GetPoints();

                Assert.That(transformedPoints, Is.EquivalentTo(expectedPoints));
            }
        }
        public MapDescription <int> GetMapDescription()
        {
            var mapDescription = new MapDescription <int>();

            // Add rooms ( - you would normally use a for cycle)
            mapDescription.AddRoom(0);
            mapDescription.AddRoom(1);
            mapDescription.AddRoom(2);
            mapDescription.AddRoom(3);

            // Add passages
            mapDescription.AddPassage(0, 1);
            mapDescription.AddPassage(0, 3);
            mapDescription.AddPassage(1, 2);
            mapDescription.AddPassage(2, 3);

            // Add room shapes
            var doorMode = new OverlapMode(1, 1);

            var squareRoom = new RoomDescription(
                GridPolygon.GetSquare(8),
                doorMode
                );
            var rectangleRoom = new RoomDescription(
                GridPolygon.GetRectangle(6, 10),
                doorMode
                );

            mapDescription.AddRoomShapes(squareRoom);
            mapDescription.AddRoomShapes(rectangleRoom);

            return(mapDescription);
        }
        public void Generate_BasicTest()
        {
            // This test cannot check if the generated configuration spaces are valid
            var mapDescription = new MapDescription <int>();
            var squareRoom     = new RoomDescription(GridPolygon.GetSquare(3), new OverlapMode(1, 0));
            var rectangleRoom  = new RoomDescription(GridPolygon.GetRectangle(4, 5), new OverlapMode(1, 1));

            mapDescription.AddRoomShapes(squareRoom);
            mapDescription.AddRoomShapes(rectangleRoom, probability: 0.5d);

            mapDescription.AddRoom(0);
            mapDescription.AddRoom(1);
            mapDescription.AddPassage(0, 1);

            mapDescription.AddRoomShapes(1, rectangleRoom, new List <Transformation>()
            {
                Transformation.Identity
            });

            // var configurationSpaces = generator.Generate(mapDescription);
            Assert.IsTrue(false);             // TODO: repair

            //Assert.AreEqual(3, configurationSpaces.GetShapesForNode(0).Count);
            //Assert.AreEqual(1, configurationSpaces.GetShapesForNode(1).Count);
        }
        public void Rectangle_LengthZeroCorners()
        {
            var polygon = GridPolygon.GetRectangle(3, 5);
            var mode    = new SpecificPositionsMode(new List <OrthogonalLine>()
            {
                new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 0)),
                new OrthogonalLine(new IntVector2(0, 5), new IntVector2(0, 5)),
                new OrthogonalLine(new IntVector2(3, 5), new IntVector2(3, 5)),
                new OrthogonalLine(new IntVector2(3, 0), new IntVector2(3, 0)),
            });
            var doorPositions = overlapModeHandler.GetDoorPositions(polygon, mode);

            var expectedPositions = new List <IDoorLine>()
            {
                new DoorLine(new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 0), OrthogonalLine.Direction.Left), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 0), OrthogonalLine.Direction.Top), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(0, 5), new IntVector2(0, 5), OrthogonalLine.Direction.Top), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(0, 5), new IntVector2(0, 5), OrthogonalLine.Direction.Right), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 5), new IntVector2(3, 5), OrthogonalLine.Direction.Right), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 5), new IntVector2(3, 5), OrthogonalLine.Direction.Bottom), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 0), new IntVector2(3, 0), OrthogonalLine.Direction.Bottom), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 0), new IntVector2(3, 0), OrthogonalLine.Direction.Left), 0),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
        public void BoudingRectangle_ReturnsBoundingBox()
        {
            {
                var p = GridPolygon.GetRectangle(2, 4);

                var boundingRectangle = p.BoundingRectangle;
                var expected          = new GridRectangle(new IntVector2(0, 0), new IntVector2(2, 4));

                Assert.AreEqual(expected, boundingRectangle);
            }

            {
                var p = new GridPolygonBuilder()
                        .AddPoint(0, 0)
                        .AddPoint(0, 6)
                        .AddPoint(3, 6)
                        .AddPoint(3, 3)
                        .AddPoint(7, 3)
                        .AddPoint(7, 0)
                        .Build();

                var boundingRectangle = p.BoundingRectangle;
                var expected          = new GridRectangle(new IntVector2(0, 0), new IntVector2(7, 6));

                Assert.AreEqual(expected, boundingRectangle);
            }
        }
        public void OverlapAlongLine_Rectangles_OverlapStart2()
        {
            var p1   = GridPolygon.GetSquare(5);
            var p2   = GridPolygon.GetRectangle(2, 3) + new IntVector2(0, -3);
            var line = new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 10));

            var result = polygonOverlap.OverlapAlongLine(p1, p2, line);

            Assert.AreEqual(0, result.Count);
        }
        public void GetAllTransformations_ReturnsCorrectCount()
        {
            var square    = GridPolygon.GetSquare(1);
            var rectangle = GridPolygon.GetRectangle(1, 2);

            var transformedSquares    = square.GetAllTransformations();
            var transformedRectangles = rectangle.GetAllTransformations();

            Assert.That(transformedSquares.Count(), Is.EqualTo(8));
            Assert.That(transformedRectangles.Count(), Is.EqualTo(8));
        }
Пример #11
0
        public void Rectangle_TwoOverlap()
        {
            var polygon           = GridPolygon.GetRectangle(3, 5);
            var mode              = new OverlapMode(1, 2);
            var doorPositions     = overlapModeHandler.GetDoorPositions(polygon, mode);
            var expectedPositions = new List <IDoorLine>()
            {
                new DoorLine(new OrthogonalLine(new IntVector2(0, 2), new IntVector2(0, 2), OrthogonalLine.Direction.Top), 1),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 3), new IntVector2(3, 3), OrthogonalLine.Direction.Bottom), 1),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
        public void Rotate_Rectangle_ReturnsRotated()
        {
            var polygon        = GridPolygon.GetRectangle(2, 5);
            var rotatedPolygon = polygon.Rotate(270);
            var expectedPoints = new List <IntVector2>()
            {
                new IntVector2(0, 0),
                new IntVector2(-5, 0),
                new IntVector2(-5, 2),
                new IntVector2(0, 2),
            };

            Assert.IsTrue(expectedPoints.SequenceEqual(rotatedPolygon.GetPoints()));
        }
        public void OverlapAlongLine_Rectangles_OverlapEnd()
        {
            var p1   = GridPolygon.GetSquare(5);
            var p2   = GridPolygon.GetRectangle(2, 3) + new IntVector2(0, 8);
            var line = new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 10));

            var result   = polygonOverlap.OverlapAlongLine(p1, p2, line);
            var expected = new List <Tuple <IntVector2, bool> >()
            {
                Tuple.Create(new IntVector2(0, 4), true),
            };

            Assert.IsTrue(expected.SequenceEqual(result));
        }
Пример #14
0
        /// <summary>
        /// Adds basic room shapes to a given map description.
        /// </summary>
        /// <typeparam name="TNode"></typeparam>
        /// <param name="mapDescription"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static MapDescription <TNode> AddClassicRoomShapes <TNode>(this MapDescription <TNode> mapDescription,
                                                                          IntVector2 scale)
        {
            var overlapScale = Math.Min(scale.X, scale.Y);
            var doorMode     = new OverlapMode(1 * overlapScale, 0);

            var squareRoom    = new RoomDescription(GridPolygon.GetSquare(6).Scale(scale), doorMode);
            var rectangleRoom = new RoomDescription(GridPolygon.GetRectangle(6, 9).Scale(scale), doorMode);
            var room1         = new RoomDescription(
                new GridPolygonBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 6)
                .AddPoint(3, 6)
                .AddPoint(3, 3)
                .AddPoint(6, 3)
                .AddPoint(6, 0)
                .Build().Scale(scale)
                , doorMode);
            var room2 = new RoomDescription(
                new GridPolygonBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 9)
                .AddPoint(3, 9)
                .AddPoint(3, 3)
                .AddPoint(6, 3)
                .AddPoint(6, 0)
                .Build().Scale(scale)
                , doorMode);
            var room3 = new RoomDescription(
                new GridPolygonBuilder()
                .AddPoint(0, 0)
                .AddPoint(0, 3)
                .AddPoint(3, 3)
                .AddPoint(3, 6)
                .AddPoint(6, 6)
                .AddPoint(6, 3)
                .AddPoint(9, 3)
                .AddPoint(9, 0)
                .Build().Scale(scale)
                , doorMode);

            mapDescription.AddRoomShapes(squareRoom, probability: 4);
            mapDescription.AddRoomShapes(rectangleRoom, probability: 2);
            mapDescription.AddRoomShapes(room1);
            mapDescription.AddRoomShapes(room2);
            mapDescription.AddRoomShapes(room3);

            return(mapDescription);
        }
Пример #15
0
        public void Rectangle_LengthZero()
        {
            var polygon           = GridPolygon.GetRectangle(3, 5);
            var mode              = new OverlapMode(0, 0);
            var doorPositions     = overlapModeHandler.GetDoorPositions(polygon, mode);
            var expectedPositions = new List <IDoorLine>()
            {
                new DoorLine(new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 5)), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(0, 5), new IntVector2(3, 5)), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 5), new IntVector2(3, 0)), 0),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 0), new IntVector2(0, 0)), 0),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
Пример #16
0
        public void Rectangle_OneOverlap()
        {
            var polygon           = GridPolygon.GetRectangle(3, 5);
            var mode              = new OverlapMode(1, 1);
            var doorPositions     = overlapModeHandler.GetDoorPositions(polygon, mode);
            var expectedPositions = new List <IDoorLine>()
            {
                new DoorLine(new OrthogonalLine(new IntVector2(0, 1), new IntVector2(0, 3)), 1),
                new DoorLine(new OrthogonalLine(new IntVector2(1, 5), new IntVector2(1, 5), OrthogonalLine.Direction.Right), 1),
                new DoorLine(new OrthogonalLine(new IntVector2(3, 4), new IntVector2(3, 2)), 1),
                new DoorLine(new OrthogonalLine(new IntVector2(2, 0), new IntVector2(2, 0), OrthogonalLine.Direction.Left), 1),
            };

            Assert.IsTrue(doorPositions.SequenceEqualWithoutOrder(expectedPositions));
        }
        public void DoOverlap_OverlappingPolygons_ReturnsTrue()
        {
            {
                var p1 = GetLShape();
                var p2 = GridPolygon.GetSquare(3);

                Assert.IsTrue(polygonOverlap.DoOverlap(p1, new IntVector2(0, 0), p2, new IntVector2(3, 0)));
            }

            {
                var p1 = GetPlusShape();
                var p2 = GridPolygon.GetRectangle(2, 3);

                Assert.IsTrue(polygonOverlap.DoOverlap(p1, new IntVector2(0, 0), p2, new IntVector2(3, 4)));
            }
        }
        public MapDescription <int> GetMapDescription()
        {
            var mapDescription = new MapDescription <int>();

            mapDescription.SetupWithGraph(GraphsDatabase.GetExample1());

            // Add room shapes
            var doorMode = new OverlapMode(1, 1);

            var squareRoom = new RoomDescription(
                GridPolygon.GetSquare(8),
                doorMode
                );
            var rectangleRoom = new RoomDescription(
                GridPolygon.GetRectangle(6, 10),
                doorMode
                );

            mapDescription.AddRoomShapes(squareRoom);
            mapDescription.AddRoomShapes(rectangleRoom);

            // Setup corridor shapes
            var corridorRoom = new RoomDescription(
                GridPolygon.GetSquare(1),
                new SpecificPositionsMode(new List <OrthogonalLine>()
            {
                new OrthogonalLine(new IntVector2(0, 0), new IntVector2(1, 0)),
                new OrthogonalLine(new IntVector2(0, 1), new IntVector2(1, 1))
            })
                );

            mapDescription.AddCorridorShapes(corridorRoom);

            // Enable corridors
            mapDescription.SetWithCorridors(true, new List <int>()
            {
                1
            });

            return(mapDescription);
        }
        public void Plus_ReturnsTranslated()
        {
            {
                var p      = GridPolygon.GetSquare(3);
                var amount = new IntVector2(2, 3);

                var translated = p + amount;
                var expected   = new GridPolygon(p.GetPoints().Select(x => x + amount));

                Assert.AreEqual(expected, translated);
            }

            {
                var p      = GridPolygon.GetRectangle(2, 4);
                var amount = new IntVector2(-3, 5);

                var translated = p + amount;
                var expected   = new GridPolygon(p.GetPoints().Select(x => x + amount));

                Assert.AreEqual(expected, translated);
            }
        }
        public void Scale_ReturnsScaled()
        {
            {
                var p      = GridPolygon.GetSquare(3);
                var factor = new IntVector2(2, 3);

                var scaled   = p.Scale(factor);
                var expected = GridPolygon.GetRectangle(6, 9);

                Assert.AreEqual(expected, scaled);
            }

            {
                /*var p = GridPolygon.GetRectangle(2, 4);
                 * var factor = new IntVector2(-3, 5);
                 *
                 * var scaled = p.Scale(factor);
                 * var expected = GridPolygon.GetRectangle(-6, 20);
                 *
                 * Assert.AreEqual(expected, scaled);*/
            }
        }
Пример #21
0
        /// <summary>
        /// Adds basic corridor room shape to a given map description.
        /// </summary>
        /// <typeparam name="TNode"></typeparam>
        /// <param name="mapDescription"></param>
        /// <param name="offsets"></param>
        /// <param name="enableCorridors"></param>
        /// <returns></returns>
        public static MapDescription <TNode> AddCorridorRoomShapes <TNode>(this MapDescription <TNode> mapDescription, List <int> offsets, bool enableCorridors = true)
        {
            foreach (var offset in offsets)
            {
                var width = offset;
                var room  = new RoomDescription(
                    GridPolygon.GetRectangle(width, 1),
                    new SpecificPositionsMode(new List <OrthogonalLine>()
                {
                    new OrthogonalLine(new IntVector2(0, 0), new IntVector2(0, 1)),
                    new OrthogonalLine(new IntVector2(width, 0), new IntVector2(width, 1)),
                })
                    );

                mapDescription.AddCorridorShapes(room);
            }

            if (enableCorridors)
            {
                mapDescription.SetWithCorridors(true, offsets);
            }

            return(mapDescription);
        }
		public MapDescription<int> GetMapDescription()
		{
			var mapDescription = new MapDescription<int>();
			mapDescription.SetupWithGraph(GraphsDatabase.GetExample2());

			// Add room shapes
			var doorMode = new OverlapMode(1, 1);

			var squareRoom = new RoomDescription(
				GridPolygon.GetSquare(8),
				doorMode
			);
			var rectangleRoom = new RoomDescription(
				GridPolygon.GetRectangle(6, 10),
				doorMode
			);

			mapDescription.AddRoomShapes(squareRoom);
			mapDescription.AddRoomShapes(rectangleRoom);

			// Add boss room shape
			var bossRoom = new RoomDescription(
				new GridPolygonBuilder()
					.AddPoint(2, 0).AddPoint(2, 1).AddPoint(1, 1).AddPoint(1, 2)
					.AddPoint(0, 2).AddPoint(0, 7).AddPoint(1, 7).AddPoint(1, 8)
					.AddPoint(2, 8).AddPoint(2, 9).AddPoint(7, 9).AddPoint(7, 8)
					.AddPoint(8, 8).AddPoint(8, 7).AddPoint(9, 7).AddPoint(9, 2)
					.AddPoint(8, 2).AddPoint(8, 1).AddPoint(7, 1).AddPoint(7, 0)
				.Build().Scale(new IntVector2(2, 2)),
				new OverlapMode(1, 1)
			);

			mapDescription.AddRoomShapes(8, bossRoom);

			return mapDescription;
		}
        public void Transform_ReturnsTransformed()
        {
            var polygon = GridPolygon.GetRectangle(2, 1);

            {
                var transformed = polygon.Transform(Transformation.Identity);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(0, 1),
                    new IntVector2(2, 1),
                    new IntVector2(2, 0)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.Rotate90);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(1, 0),
                    new IntVector2(1, -2),
                    new IntVector2(0, -2)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.Rotate180);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(0, -1),
                    new IntVector2(-2, -1),
                    new IntVector2(-2, 0)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.Rotate270);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(-1, 0),
                    new IntVector2(-1, 2),
                    new IntVector2(0, 2)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.MirrorX);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(2, 0),
                    new IntVector2(2, -1),
                    new IntVector2(0, -1)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.MirrorY);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(-2, 0),
                    new IntVector2(-2, 1),
                    new IntVector2(0, 1)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.Diagonal13);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(0, 2),
                    new IntVector2(1, 2),
                    new IntVector2(1, 0)
                }));
            }

            {
                var transformed = polygon.Transform(Transformation.Diagonal24);
                Assert.That(transformed.GetPoints(), Is.EquivalentTo(new List <IntVector2>()
                {
                    new IntVector2(0, 0),
                    new IntVector2(0, -2),
                    new IntVector2(-1, -2),
                    new IntVector2(-1, 0)
                }));
            }
        }