Esempio n. 1
0
        public void IntersectTest(IRectangle rectangle1, IRectangle rectangle2, IRectangle rectangleExpected)
        {
            TraceFile.SetName("IntersectTest");
            var result = Service.Intersect(rectangle1, rectangle2);

            if (rectangleExpected == null)
            {
                Assert.IsNull(result);
            }
            else
            {
                Assert.AreEqual(rectangleExpected.Left(), result.Left(), 0, "Left");
                Assert.AreEqual(rectangleExpected.Top(), result.Top(), 0, "Top");
                Assert.AreEqual(rectangleExpected.Width(), result.Width(), 0, "Width");
                Assert.AreEqual(rectangleExpected.Height(), result.Height(), 0, "Height");
            }
        }
Esempio n. 2
0
        public IRectangle Intersect(IRectangle rectangle1, IRectangle rectangle2)
        {
            if (rectangle1 == null || rectangle2 == null)
            {
                return(null);
            }

            var maxLeft  = Math.Max(rectangle1.Left(), rectangle2.Left());
            var minRight = Math.Min(rectangle1.Right(), rectangle2.Right());

            var maxTop    = Math.Max(rectangle1.Top(), rectangle2.Top());
            var minBottom = Math.Min(rectangle1.Bottom(), rectangle2.Bottom());

            if (maxLeft < minRight && maxTop < minBottom)
            {
                return(new Rectangle(minRight - maxLeft, minBottom - maxTop, maxLeft, maxTop));
            }
            return(null);
        }