Exemple #1
0
        public void XorRectRegion(Rectangle newRectangle)
        {
            //Step 0) Resize rectangle. Anything outside regionRectangle does not interest us as it will not be added to In
            int backMinX = this.region.getCoord()[0];
            int backMaxX = this.region.getCoord()[1];
            int backMinY = this.region.getCoord()[2];
            int backMaxY = this.region.getCoord()[3];

            Rectangle back       = new Rectangle(backMinX, backMaxX, backMinY, backMaxY);
            Rectangle Rintersect = Rectangle.intersection(back, newRectangle);

            if (!Rintersect.getInvalid())
            {
                // Step 1) Find Intersection with Rectangles
                ListOperations intersect = ListOperations.regionListIntersect(this.In, newRectangle);

                // Step 2) Add rectangles except for the intersection
                this.In = addNotInIntersect(intersect, newRectangle);

                // Step 3) do the offset thing
                this.OffsetRegion();
            }
            else
            {
                this.OrRectRegion(newRectangle);
            }

            this.region.RegionRect(In);
        }
Exemple #2
0
        public static Rectangle intersection(Rectangle a, Rectangle b)
        {
            //Falls a oder b invalid gebe einen invalid rectangle zurück
            if((a.getInvalid() || b.getInvalid()))
            {
                Rectangle d = new Rectangle(0, -1, 0, 0);
                return d;
            }
            // get intersection x_Axis:
            int minX = Math.Max(a.getCoord()[0], b.getCoord()[0]);
            int maxX = Math.Min(a.getCoord()[1], b.getCoord()[1]);

            // get Intersection y-Axis:
            int minY = Math.Max(a.getCoord()[2], b.getCoord()[2]);
            int maxY = Math.Min(a.getCoord()[3], b.getCoord()[3]);

            //Falls intersection keinen sinn macht, z.B. minX>maxX, dann setzt konstruktor invalid auf true;
            Rectangle c = new Rectangle(minX, maxX, minY, maxY);
            return c;
        }