public NonoverlappingRectangleCollectiοn WithOffset(Point offset)
        {
            var result = new NonoverlappingRectangleCollectiοn(this);

            result.Offset(offset);
            return(result);
        }
        /// <summary> Returns a new polygon with the area of the specified polygon added to its area. </summary>
        /// /// <param name="polygon"> The polygon to be added to this polygon. May overlap. </param>
        public void Add(NonoverlappingRectangleCollectiοn polygon, Point offset = default(Point))
        {
            polygon.CheckInvariants();
            foreach (var rectangle in polygon)
            {
                this.Add(rectangle, offset);
            }

            this.Simplify();
        }
        /// <summary> Gets the vertical coordinate where the specified could be added to the current polygon without overlap. </summary>
        /// <param name="polygon"> The polygon to be added to this </param>
        /// <param name="offset"> The minimum y coordinate where the polygon could be placed. The x coordinate is an ordinary offset. </param>
        private double GetVerticalOverlap(NonoverlappingRectangleCollectiοn polygon, Point offset = default(Point))
        {
            Contract.Requires(polygon != null);

            double largestOverlap = 0;

            foreach (Rect r in polygon)
            {
                foreach (Rect element in this)
                {
                    double overlap = element.Bottom - (r.Y + offset.Y);
                    if (overlap > largestOverlap)
                    {
                        largestOverlap = overlap;
                    }
                }
            }
            return(largestOverlap);
        }
        /// <summary> Gets the hortizontal coordinate where the specified could be added to the current polygon without overlap. </summary>
        /// <param name="polygon"> The polygon to be added to this </param>
        /// <param name="offset"> The minimum x coordinate where the polygon could be placed. The y coordinate is an ordinary offset. </param>
        private double GetHorizontalOverlap(NonoverlappingRectangleCollectiοn polygon, Point offset = default(Point))
        {
            Contract.Requires(polygon != null);

            double largestHorizontalOverlap = 0;

            foreach (Rect r in polygon)
            {
                foreach (Rect element in this)
                {
                    double horizontalOverlap = element.Right - (r.X + offset.X);
                    if (horizontalOverlap > largestHorizontalOverlap)
                    {
                        largestHorizontalOverlap = horizontalOverlap;
                    }
                }
            }
            return(largestHorizontalOverlap);
        }
 /// <summary> Adds the specified polygon adjacently below the current polygon, where the left of the specified polygon will be identified with the line x = 0 in the reference frame of this polygon. </summary>
 /// <param name="polygon"> The polygon to place. </param>
 /// <param name="placementBottom"> The y coordinate where the specified polygon was placed. </param>
 /// <param name="offset"> The offset to add to the specified polygon. The polygon is placed at least at the specified y coordinate. </param>
 public void AddBottom(NonoverlappingRectangleCollectiοn polygon, out double placementBottom, Point offset = default(Point))
 {
     placementBottom = GetVerticalOverlap(polygon, offset);
     this.Add(polygon, new Point(offset.X, offset.Y + placementBottom));
 }
        public void AddBottom(NonoverlappingRectangleCollectiοn polygon, Point offset = default(Point))
        {
            double dummy;

            AddBottom(polygon, out dummy, offset);
        }
 /// <summary> Adds the specified polygon adjacently to the right of the current polygon, where the top of the specified polygon will be identified with the line y = 0 in the reference frame of this polygon. </summary>
 /// <param name="polygon"> The polygon to place. </param>
 /// <param name="placementRight"> The x coordinate where the specified polygon was placed. </param>
 /// /// <param name="offset"> The offset to add to the specified polygon. The polygon is placed at least at the specified x coordinate. </param>
 public void AddRight(NonoverlappingRectangleCollectiοn polygon, out double placementRight, Point offset = default(Point))
 {
     placementRight = GetHorizontalOverlap(polygon, offset);
     this.Add(polygon, new Point(offset.X + placementRight, offset.Y));
 }
 public void Add(NonoverlappingRectangleCollectiοn polygon, double xOffset, double yOffset)
 {
     this.Add(polygon, new Point(xOffset, yOffset));
 }
 /// <summary> Clones the specified nonoverlapping rectangle collection. </summary>
 /// <param name="clone"> The collection to clone. </param>
 public NonoverlappingRectangleCollectiοn(NonoverlappingRectangleCollectiοn clone) : this(clone.ToSingleton())
 {
 }