示例#1
0
        public void Allocate()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var grid = new CoordGrid(perimeter);

            Assert.Equal(2257, grid.Available.Count);
            var allocate = new Polygon
                           (
                new[]
            {
                new Vector3(10, 10),
                new Vector3(20, 10),
                new Vector3(20, 20),
                new Vector3(10, 20)
            }
                           );

            grid.Allocate(allocate);
            Assert.Equal(2136, grid.Available.Count);
        }
示例#2
0
        public void AvailableRandom()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var grid     = new CoordGrid(perimeter);
            var allocate = new Polygon
                           (
                new[]
            {
                new Vector3(10, 10),
                new Vector3(20, 10),
                new Vector3(20, 20),
                new Vector3(10, 20)
            }
                           );

            grid.Allocate(allocate);
            var point = grid.AvailableRandom();

            Assert.Contains(point, grid.Available);
            Assert.Equal(42.0, point.X);
            Assert.Equal(8.0, point.Y);
        }
示例#3
0
        public void AllocatedNearTo()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var allocated = new List <Polygon>
            {
                new Polygon
                (
                    new []
                {
                    new Vector3(),
                    new Vector3(8, 0),
                    new Vector3(8, 9),
                    new Vector3(0, 9)
                }
                ),
                new Polygon
                (
                    new []
                {
                    new Vector3(52, 0),
                    new Vector3(60, 0),
                    new Vector3(60, 6),
                    new Vector3(52, 6)
                }
                ),
                new Polygon
                (
                    new []
                {
                    new Vector3(24, 33),
                    new Vector3(32, 33),
                    new Vector3(32, 36),
                    new Vector3(24, 36)
                }
                )
            };
            var grid = new CoordGrid(perimeter);

            foreach (Polygon polygon in allocated)
            {
                grid.Allocate(polygon);
            }
            var nearPoint = grid.AllocatedNearTo(new Vector3(26.6, 34.1));

            Assert.Equal(27, nearPoint.X);
            Assert.Equal(36, nearPoint.Y);
        }