예제 #1
0
        /// <summary>
        /// Returns true if this rectangle overlaps with the given box.
        /// </summary>
        /// <param name="box">Box.</param>
        public bool Overlaps(BoxF2D box)
        {
            // Yes, I know this code can be shorter but it would turn into a mess!
            if (box.Contains(this.BottomLeft) || box.Contains(this.BottomRight) ||
                box.Contains(this.TopLeft) || box.Contains(this.TopRight))
            {
                return(true);
            }
            if (this.Contains(box.Corners [0]) || this.Contains(box.Corners [2]) ||
                this.Contains(box.Corners [3]) || this.Contains(box.Corners [0]))
            {
                return(true);
            }

            List <LineF2D> lines = new List <LineF2D> ();

            lines.Add(new LineF2D(this.BottomLeft, this.BottomRight, true));
            lines.Add(new LineF2D(this.BottomRight, this.TopRight, true));
            lines.Add(new LineF2D(this.TopRight, this.TopLeft, true));
            lines.Add(new LineF2D(this.TopLeft, this.BottomLeft, true));
            foreach (LineF2D line in (box as IEnumerable <LineF2D>))
            {
                foreach (LineF2D otherLine in lines)
                {
                    if (line.Intersects(otherLine))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        public bool Overlaps(BoxF2D box)
        {
            if (box.Contains(this.BottomLeft) || box.Contains(this.BottomRight) || (box.Contains(this.TopLeft) || box.Contains(this.TopRight)) || (this.Contains(box.Corners[0]) || this.Contains(box.Corners[2]) || (this.Contains(box.Corners[3]) || this.Contains(box.Corners[0]))))
            {
                return(true);
            }
            List <LineF2D> lineF2DList = new List <LineF2D>();

            lineF2DList.Add(new LineF2D(this.BottomLeft, this.BottomRight, true));
            lineF2DList.Add(new LineF2D(this.BottomRight, this.TopRight, true));
            lineF2DList.Add(new LineF2D(this.TopRight, this.TopLeft, true));
            lineF2DList.Add(new LineF2D(this.TopLeft, this.BottomLeft, true));
            foreach (LineF2D lineF2D in (IEnumerable <LineF2D>)box)
            {
                foreach (LineF2D line in lineF2DList)
                {
                    if (lineF2D.Intersects(line))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }