Exemplo n.º 1
0
        public static Rectangle Intersect(RectangleWithLongs imageArea, RectangleWithLongs requestedArea)
        {
            if (requestedArea.Width < 0)
            {
                requestedArea.X      = requestedArea.Width + requestedArea.X;
                requestedArea.Width *= -1;
            }
            if (requestedArea.Height < 0)
            {
                requestedArea.Y       = requestedArea.Height + requestedArea.Y;
                requestedArea.Height *= -1;
            }

            long x1 = Math.Max(imageArea.X, requestedArea.X);
            long x2 = Math.Min(imageArea.X + imageArea.Width, requestedArea.X + requestedArea.Width);
            long y1 = Math.Max(imageArea.Y, requestedArea.Y);
            long y2 = Math.Min(imageArea.Y + imageArea.Height, requestedArea.Y + requestedArea.Height);

            if (x2 >= x1 && y2 >= y1 && (x2 - x1) != 0 && (y2 - y1) != 0)
            {
                return(new Rectangle((int)x1, (int)y1, (int)(x2 - x1), (int)(y2 - y1)));
            }

            return(Rectangle.Empty);
        }
Exemplo n.º 2
0
        public void TestRectangleWithLongsIntersection()
        {
            Size testSize = new Size(100, 100);

            Assert.AreEqual(new Rectangle(0, 0, 100, 100),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 100, 100)));
            Assert.AreEqual(new Rectangle(0, 0, 100, 100),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 200, 200)));
            Assert.AreEqual(new Rectangle(0, 0, 100, 100),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 200, 100)));
            Assert.AreEqual(new Rectangle(0, 0, 100, 100),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 100, 200)));
            Assert.AreEqual(new Rectangle(0, 0, 30, 40),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 30, 40)));
            Assert.AreEqual(new Rectangle(30, 40, 10, 10),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(30, 40, 10, 10)));

            Assert.AreEqual(new Rectangle(0, 0, 30, 40),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(-5, 0, 35, 40)));
            Assert.AreEqual(new Rectangle(0, 0, 30, 40),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, -5, 30, 45)));
            Assert.AreEqual(new Rectangle(0, 0, 100, 20),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(-5, -30, 200, 50)));

            Assert.AreEqual(new Rectangle(30, 0, 20, 80),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(50, 80, -20, -150)));
            Assert.AreEqual(new Rectangle(0, 0, 100, 100),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(100, 100, -100, -100)));

            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 0, 0)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 0, 100)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 100, 0)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, 0, -100)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(0, 0, -100, 0)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(100, 100, 0, 0)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(100, 100, 100, 100)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(-5, -30, 4, 29)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(-5, -30, 5, 30)));
            Assert.AreEqual(new Rectangle(0, 0, 0, 0),
                            RectangleWithLongs.Intersect(testSize, new RectangleWithLongs(-5, -30, -100, -100)));
        }
Exemplo n.º 3
0
 public Transformation(Bitmap originalImage, RectangleWithLongs requestedArea)
 {
     RequestedArea    = requestedArea;
     ImageToTransform = originalImage;
 }
 public CounterClockwiseRotation(Bitmap originalImage, RectangleWithLongs requestedArea) : base(originalImage, requestedArea)
 {
 }
Exemplo n.º 5
0
 public HorizontalFlip(Bitmap originalImage, RectangleWithLongs requestedArea) : base(originalImage, requestedArea)
 {
 }
Exemplo n.º 6
0
 public TransformableImage(Transformation transformation, RectangleWithLongs requestedArea, Bitmap imageToTransform)
 {
     RequestedArea    = requestedArea;
     ImageToTransform = imageToTransform;
     Transformation   = transformation;
 }