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); }
public void AndRectRegion(Rectangle newRectangle) { ListOperations newIn = new ListOperations(); Rectangle a; for (int c = In.Count() - 1; c >= 0; c--) { a = Rectangle.intersection(this.In[c], newRectangle); this.CutOrIn(newIn, newRectangle, true); } this.OffsetRegion(); this.region.RegionRect(newIn); this.In = newIn; }
private ListOperations addNotInIntersect(ListOperations intersect, Rectangle newRectangle) { ListOperations result = new ListOperations(); bool added = false; // Step 1) Add In. All rectangles inside In are disjoint. foreach (Rectangle item in this.In) { added = false; for (int c = intersect.Count() - 1; c >= 0; c--) { //letztes Argument ist das XOR=true (die vereinigungsart); if (!Rectangle.intersection(intersect[c], item).getInvalid() && !added) { result.AddRange(Rectangle.AddIntoRectangle(intersect[c], item, true)); added = true; } if ((c == 0) && (!added)) { result.AddRange(Rectangle.AddIntoRectangle(intersect[c], item, true)); } } } // Step 2 add XOR to everywhere except for the intersections Window w = new Window(); w.In = intersect; int length = w.In.Count(); w.CutOrIn(intersect, newRectangle, false); w.In.RemoveRange(0, length); for (int i = w.In.Count() - 1; i >= 0; i--) { if (i > w.In.Count() - 1) { i = w.In.Count() - 1; } w.In = w.In.simplifyByX(w.In, i); if (i > w.In.Count() - 1) { i = w.In.Count() - 1; } w.In = w.In.simplifyByY(w.In, i); } result.AddRange(w.In); return(result); }
public static ListOperations AddIntoRectangle(Rectangle old, Rectangle add, bool XOR) { ListOperations aList = new ListOperations(); int oldMinX = old.getCoord()[0]; int oldMaxX = old.getCoord()[1]; int oldMinY = old.getCoord()[2]; int oldMaxY = old.getCoord()[3]; int addMinX = add.getCoord()[0]; int addMaxX = add.getCoord()[1]; int addMinY = add.getCoord()[2]; int addMaxY = add.getCoord()[3]; if (subset(old,add)) { if (XOR) { Rectangle upper = new Rectangle(oldMinX, oldMaxX, oldMaxY + 1, addMaxY); Rectangle lower = new Rectangle(oldMinX, oldMaxX, addMinY, oldMinY - 1); Rectangle left = new Rectangle(addMinX, oldMinX - 1, addMinY, addMaxY); Rectangle right = new Rectangle(oldMaxX + 1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); aList.validAdd(right, true); return aList; } aList.Add(add); return aList; } if(subset(add, old)) { if (XOR) { Rectangle upper = new Rectangle(oldMinX, oldMaxX, oldMaxY + 1, addMaxY); Rectangle lower = new Rectangle(oldMinX, oldMaxX, addMinY, oldMinY - 1); Rectangle left = new Rectangle(addMinX, oldMinX - 1, addMinY, addMaxY); Rectangle right = new Rectangle(oldMaxX + 1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); aList.validAdd(right, true); return aList; } return aList; } if((Rectangle.intersection(old,add).getInvalid())) { aList.Add(add); return aList; } //new Rectangle between old bounds if ((oldMinX <= addMinX) && (addMaxX <= oldMaxX)) { Rectangle lower = new Rectangle(addMinX, addMaxX, addMinY, oldMinY-1); Rectangle upper = new Rectangle(addMinX, addMaxX, oldMaxY+1, addMaxY); aList.validAdd(lower, true); aList.validAdd(upper, true); return aList; } //new Rectangle exceeds old bounds if ((addMinX <= oldMinX) && (oldMaxX <= addMaxX)) { Rectangle upper = new Rectangle(oldMinX, oldMaxX, oldMaxY+1, addMaxY); Rectangle lower = new Rectangle(oldMinX, oldMaxX, addMinY, oldMinY-1); Rectangle left = new Rectangle(addMinX, oldMinX-1, addMinY, addMaxY); Rectangle right = new Rectangle(oldMaxX+1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); aList.validAdd(right, true); return aList; } //new Rectangle left of old bounds if ((oldMinX <= addMaxX) && (addMaxX <= oldMaxX)) { Rectangle upper = new Rectangle(oldMinX, addMaxX, oldMaxY+1, addMaxY); Rectangle lower = new Rectangle(oldMinX, addMaxX, addMinY, oldMinY-1); Rectangle left = new Rectangle(addMinX, oldMinX-1, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); return aList; } //new Rectangle right of old bounds if ((addMinX <= oldMaxX) && (oldMaxX <= addMaxX)) { Rectangle upper = new Rectangle(addMinX, oldMaxX, oldMaxY+1, addMaxY); Rectangle lower = new Rectangle(addMinX, oldMaxX, addMinY, oldMinY-1); Rectangle right = new Rectangle(oldMaxX+1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(right, true); return aList; } return aList; }