示例#1
0
        private static Polygon PlaceAdjacentToFootprint(Polygon suitBox, List <Polygon> footPrints, bool diagonal)
        {
            Polygon footPrint = null;

            foreach (var ftPrint in footPrints)
            {
                footPrint = Shaper.PlaceOrthogonal(ftPrint, suitBox, true, true);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                footPrint = Shaper.PlaceOrthogonal(ftPrint, suitBox, true, false);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                footPrint = Shaper.PlaceOrthogonal(ftPrint, suitBox, false, true);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                footPrint = Shaper.PlaceOrthogonal(ftPrint, suitBox, false, false);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                if (!diagonal)
                {
                    continue;
                }
                footPrint = Shaper.PlaceDiagonal(ftPrint, suitBox, Corner.NE);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                footPrint = Shaper.PlaceDiagonal(ftPrint, suitBox, Corner.SE);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                footPrint = Shaper.PlaceDiagonal(ftPrint, suitBox, Corner.NW);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
                footPrint = Shaper.PlaceDiagonal(ftPrint, suitBox, Corner.SW);
                if (!footPrint.Intersects(footPrints))
                {
                    return(footPrint);
                }
            }
            return(footPrint);
        }
示例#2
0
        private static Polygon PlaceAdjacentToSuite(Polygon lastBox, Polygon suitBox,
                                                    List <Polygon> footPrints,
                                                    bool northeast, bool minCoord, bool diagonal)
        {
            var footPrint = Shaper.PlaceOrthogonal(lastBox, suitBox, northeast, minCoord);

            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            footPrint = Shaper.PlaceOrthogonal(lastBox, suitBox, northeast, !minCoord);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            footPrint = Shaper.PlaceOrthogonal(lastBox, suitBox, !northeast, minCoord);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            footPrint = Shaper.PlaceOrthogonal(lastBox, suitBox, !northeast, !minCoord);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            var corners = new List <Corner>();

            if (!diagonal)
            {
                return(null);
            }
            if (northeast)
            {
                corners.Add(Corner.NE);
                corners.Add(Corner.NW);
                corners.Add(Corner.SE);
                corners.Add(Corner.SW);
            }
            else
            {
                corners.Add(Corner.SW);
                corners.Add(Corner.SE);
                corners.Add(Corner.NW);
                corners.Add(Corner.NE);
            }
            footPrint = Shaper.PlaceDiagonal(lastBox, suitBox, corners[0]);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            footPrint = Shaper.PlaceDiagonal(lastBox, suitBox, corners[1]);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            footPrint = Shaper.PlaceDiagonal(lastBox, suitBox, corners[2]);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            footPrint = Shaper.PlaceDiagonal(lastBox, suitBox, corners[3]);
            if (!footPrint.Intersects(footPrints))
            {
                return(footPrint);
            }
            return(null);
        }
示例#3
0
        public void PlaceOrthogonal()
        {
            var polygon = new Polygon
                          (
                new[]
            {
                Vector3.Origin,
                new Vector3(10.0, 0.0),
                new Vector3(10.0, 6.0),
                new Vector3(0.0, 6.0)
            }
                          );
            var place = new Polygon
                        (
                new[]
            {
                Vector3.Origin,
                new Vector3(6.0, 0.0),
                new Vector3(6.0, 3.0),
                new Vector3(0.0, 3.0)
            }
                        );

            // Horizontal polygon, northeast, minimum coord
            place = Shaper.PlaceOrthogonal(polygon, place, true, true);
            var points = place.Vertices;

            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 6.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 9.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 6.0) && Shaper.NearEqual(p.Y, 6.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 6.0) && Shaper.NearEqual(p.Y, 9.0));

            // Vertical polygon, northeast, minimum coord
            polygon = polygon.Rotate(Vector3.Origin, 90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, true, true);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 6.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 3.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 3.0) && Shaper.NearEqual(p.Y, 6.0));

            // Horizontal polygon, northeast, maximum coord
            polygon = polygon.Rotate(Vector3.Origin, -90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, true, false);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 10.0) && Shaper.NearEqual(p.Y, 6.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 10.0) && Shaper.NearEqual(p.Y, 9.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 4.0) && Shaper.NearEqual(p.Y, 6.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 4.0) && Shaper.NearEqual(p.Y, 9.0));

            // Vertical polygon, northeast, maximum coord
            polygon = polygon.Rotate(Vector3.Origin, 90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, true, false);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 10.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 3.0) && Shaper.NearEqual(p.Y, 10.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 4.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 3.0) && Shaper.NearEqual(p.Y, 4.0));

            // Horizontal polygon, southwest, minimum coord
            polygon = polygon.Rotate(Vector3.Origin, -90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, false, true);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 6.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 0.0) && Shaper.NearEqual(p.Y, -3.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 6.0) && Shaper.NearEqual(p.Y, -3.0));

            // Vertical polygon, southwast, minimum coord
            polygon = polygon.Rotate(Vector3.Origin, 90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, false, true);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -6.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -9.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -6.0) && Shaper.NearEqual(p.Y, 6.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -9.0) && Shaper.NearEqual(p.Y, 6.0));

            // Horizontal polygon, southwest, maximum coord
            polygon = polygon.Rotate(Vector3.Origin, -90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, false, false);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 4.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 10.0) && Shaper.NearEqual(p.Y, 0.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 4.0) && Shaper.NearEqual(p.Y, -3.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, 10.0) && Shaper.NearEqual(p.Y, -3.0));

            // Vertical polygon, southwest, maximum coord
            polygon = polygon.Rotate(Vector3.Origin, 90.0);
            place   = Shaper.PlaceOrthogonal(polygon, place, false, false);
            points  = place.Vertices;
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -6.0) && Shaper.NearEqual(p.Y, 10.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -9.0) && Shaper.NearEqual(p.Y, 10.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -6.0) && Shaper.NearEqual(p.Y, 4.0));
            Assert.Contains(points, p => Shaper.NearEqual(p.X, -9.0) && Shaper.NearEqual(p.Y, 4.0));
        }