コード例 #1
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 CoordinateGrid(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);
        }
コード例 #2
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 []
                {
                    Vector3.Origin,
                    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 CoordinateGrid(perimeter);

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

            Assert.Equal(26.5, nearPoint.X);
            Assert.Equal(35.5, nearPoint.Y);
        }
コード例 #3
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 CoordinateGrid(perimeter);

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

            grid.Allocate(allocate1);
            Assert.Equal(2060, grid.Available.Count);
            var allocate2 = new Polygon
                            (
                new[]
            {
                new Vector3(30, 10),
                new Vector3(40, 10),
                new Vector3(40, 30),
                new Vector3(30, 30)
            }
                            );

            grid = new CoordinateGrid(perimeter);
            var allocate = new List <Polygon> {
                allocate1, allocate2
            };

            grid.Allocate(allocate);
            Assert.Equal(1860, grid.Available.Count);
        }