/// <summary>Calculates intersection of the image and the render filter region in the coordinate system relative to the image. /// </summary> /// <returns> /// <code>null</code> if the image is fully covered and therefore is completely cleaned, /// <see cref="System.Collections.IList{E}"/> /// of /// <see cref="iText.Kernel.Geom.Rectangle"/> /// objects otherwise. /// </returns> private IList <Rectangle> GetImageAreasToBeCleaned(ImageRenderInfo image) { Rectangle imageRect = CalcImageRect(image); if (imageRect == null) { return(null); } IList <Rectangle> areasToBeCleaned = new List <Rectangle>(); foreach (Rectangle region in regions) { Rectangle intersectionRect = GetRectanglesIntersection(imageRect, region); if (intersectionRect != null) { if (imageRect.EqualsWithEpsilon(intersectionRect)) { // true if the image is completely covered return(null); } areasToBeCleaned.Add(TransformRectIntoImageCoordinates(intersectionRect, image.GetImageCtm())); } } return(areasToBeCleaned); }
public virtual void GetIntersectionTest01() { //Cases where there is an intersection rectangle Rectangle main; Rectangle second; Rectangle actual; Rectangle expected; bool areEqual; main = new Rectangle(2, 2, 8, 8); //A. Main rectangle is greater in both dimension than second rectangle second = new Rectangle(4, 8, 4, 4); //1.Middle top expected = new Rectangle(4, 8, 4, 2); actual = main.GetIntersection(second); areEqual = expected.EqualsWithEpsilon(actual); //2.Middle Right second.MoveRight(4); expected = new Rectangle(8, 8, 2, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //3.Right middle second.MoveDown(4); expected = new Rectangle(8, 4, 2, 4); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //4.Bottom right second.MoveDown(4); expected = new Rectangle(8, 2, 2, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //5.Bottom middle second.MoveLeft(4); expected = new Rectangle(4, 2, 4, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //6.Bottom Left second.MoveLeft(4); expected = new Rectangle(2, 2, 2, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //7.Left Middle second.MoveUp(4); expected = new Rectangle(2, 4, 2, 4); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //8.Left Top second.MoveUp(4); expected = new Rectangle(2, 8, 2, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //B. Main rectangle is greater in width but not height than second rectangle //1. Left second = new Rectangle(0, 0, 4, 12); expected = new Rectangle(2, 2, 2, 8); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //2. Middle second.MoveRight(4); expected = new Rectangle(4, 2, 4, 8); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //3. Right second.MoveRight(4); expected = new Rectangle(8, 2, 2, 8); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //C. Main rectangle is greater in height but not width than second rectangle //1. Top second = new Rectangle(0, 8, 12, 4); expected = new Rectangle(2, 8, 8, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //2. Middle second.MoveDown(4); expected = new Rectangle(2, 4, 8, 4); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //3. Bottom second.MoveDown(4); expected = new Rectangle(2, 2, 8, 2); actual = main.GetIntersection(second); areEqual = areEqual && (expected.EqualsWithEpsilon(actual)); //Check if any have failed NUnit.Framework.Assert.IsTrue(areEqual); }